-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: problem with Date
PostPosted: Mon Sep 01, 2003 9:58 pm 
Beginner
Beginner

Joined: Wed Aug 27, 2003 8:53 pm
Posts: 34
Hi,

I use java.util.Date for one property in my bean, I also set up "date" type in property in my mapping file. When I insert a row into db table, then load it
by using its auto-generated id, I found the inserted date column value and the retrieved date column value are different. This is the reason why they are not equal when I compare them using equals() method. If I remove Date from my bean and mapping file, and use other types, there will be no problem.

I am wondering how you guys handle this problem with Date type?

regards,


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2003 10:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Of course!

A java.util.Date represents a timestamp.


The Hibernate "date" type, sanely, represents a date.


Use the Hibernate "timestamp" type, which is the default mapping for a java.util.Date.

Note also that some JDBC drivers truncate or otherwise mangle java.sql.Timestamps, so equals() might not quite work anyway.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2003 10:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
How are the dates different?

You said you map with "date" as the type. Realize that this correlates to the DATE sql type, which on most DBs keeps only the date portion and drops the time portion. If this is what you are seeing, map using "timestamp" as the type instead.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2003 10:36 pm 
Beginner
Beginner

Joined: Wed Aug 27, 2003 8:53 pm
Posts: 34
Yes, you are right guys. Just tested it, and this solved my problem.

So much to learn about Hibernate!

regards,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.