I am storing date in mysql database using field of type DATE :
@Temporal(TemporalType.DATE)
@Column(name="RECIEVING_DATE")
private Date recieving_date;
// getters and setters
but when hibernate saves it , date is saved in type of datetime format, i.e. it doesn't store just 2015-02-23 but 2015-02-23 00:00:00.
The code I am using for inserting the date
String recieving_date = request.getParameter("recieving_date");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
java.sql.Date ds = null;
try {
Date date = df.parse(recieving_date);
ds=new java.sql.Date(date.getTime());
} catch (ParseException e1) {
System.out.println("Exception occured in parsing date : "+e1);
}
doc_mvmnt.setRecieving_date(ds);
Now , I can change type by running alter table query myself in database , but that will be painful every time. How can I tell hibernate to keep the type I want . And further , if this is possible , is it possible to define the size of varchar and integers using hibernate. Please help