-->
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.  [ 3 posts ] 
Author Message
 Post subject: Query by Date Object
PostPosted: Thu Dec 11, 2003 10:06 pm 
Beginner
Beginner

Joined: Tue Sep 02, 2003 3:25 pm
Posts: 21
Location: Kingston Jamaica, West Indies
Using java.sql.Date in the HQL , using a prepared statement it fails to return the correct result.

When i query by the string rep of the Date this works , but what about the object comparison itself.

Using Hibernate.DATE


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2003 7:39 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
use equals, not ==
beware the precision, some java.util.date can be more precise than the one you get from DB.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2003 7:59 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
epbernard wrote:
use equals, not ==
beware the precision, some java.util.date can be more precise than the one you get from DB.


There is something more to care about: by default, Hibernate will map java.util.Date instances to a JDBC java.sql.Timestamp (unless you specify a type date or time - not timestamp in your mapping file).

When reading your data back, your original date properties will be initialized with java.sql.Timestamp rather than java.util.Date... This may cause problems later in your code if you try to compare these fields with other java.util.Date - see http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Timestamp.html

To avoid problems, we used to implement a special UserType that converts timestamps back to util.dates.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.