-->
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.  [ 2 posts ] 
Author Message
 Post subject: NamedQuery date precision problem
PostPosted: Tue Aug 01, 2006 6:10 am 
Beginner
Beginner

Joined: Fri Sep 16, 2005 7:51 am
Posts: 25
Hello there,

I have a named query :

@javax.persistence.NamedQuery(
name="query.TaskDAO.loadTaskByDate",
query="from Task t where t.deadlineDate between :beforeDate and :afterDate"
)

and a POJO

@Entity
public class Task extends DescriptibleObject implements Serializable {
(...)

@Temporal(TemporalType.TIMESTAMP)
private Date deadlineDate;

(...)

When I run the named query to fetch some "Task" objects with 'deadlineDate' between two given date, I got an empty result set, even with data that fits in the DB

In the logs, I have ( hibernate log in DEBUG level)

2006-08-01 11:50:17,546 DEBUG org.hibernate.loader.hql.QueryLoader - bindNamedParameters() Wed Jul 19 00:00:00 CEST 2006 -> beforeDate [1]
2006-08-01 11:50:17,546 DEBUG org.hibernate.type.DateType - binding '19 juillet 2006' to parameter: 1
2006-08-01 11:50:17,546 DEBUG org.hibernate.loader.hql.QueryLoader - bindNamedParameters() Wed Jul 19 23:59:59 CEST 2006 -> afterDate [2]
2006-08-01 11:50:17,546 DEBUG org.hibernate.type.DateType - binding '19 juillet 2006' to parameter: 2
2006-08-01 11:50:17,546 DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
2006-08-01 11:50:17,546 DEBUG org.hibernate.loader.Loader - processing result set
2006-08-01 11:50:17,546 DEBUG org.hibernate.loader.Loader - done processing result set (0 rows)


Everything is correct (parameter binding, aso), and after some testing, I suspect the precision of the date to be the cause of my problem.

But since I annotated the precision with the @Temporal annotation, I don't know where to seek elsewhere to fix my problem...

Any help would be greatly appreciated !

Thanks in advance,

sne.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 01, 2006 4:04 pm 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
How do you set these dates?
query.setDate(date) ?

I think you should use
query.setTimestamp(date)

http://www.hibernate.org/hib_docs/v3/ap ... .util.Date)

@Temporal is for entity's property, it has nothing to do with query - that's how date is written into db - just date, just time or full timestamp. You manage your query precision by using correct setters.

Rgds, Ales


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