• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Date mapping

 
hani Ibrahim
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have delimma with mapping date between pojo and mysql date. what i have like this:
GregorianCalendar calender = new GregorianCalendar();
String SQL_QUERY = "select foo.date" +
" from Foo foo";

Query query = session.createQuery(SQL_QUERY);
for (Iterator it = query.iterate(); it.hasNext();) {
Date date = (Date) it.next();
System.out.println("date: " +
date);
if(date==calender.getTime()){
System.out.println("HELLO the same");
}else{
System.out.println("HELLO arent the same");
}

}
----------
The problem is the Date that comes from DB like this 2009-01-02 and the Date of java object comes with hours,seconds .I need it pure Date object without hours,minutes,seconds.
And is that handled in Hibernate
Please advice
 
dhwani mathur
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Date that comes from DB like this 2009-01-02



hi

as per date comes in that format ......you can
format your
java date by using SimleDateFormat class
there are many methods like format() and just pass on the format you need and the rest i hope you can compare .




Life is beautiful just as rose but still carries some thorns with it.

 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, could you please show how your mapping of Dates ?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic