-->
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: How can i get "year" value from date fied in HQL?
PostPosted: Mon Oct 13, 2008 8:11 am 
Newbie

Joined: Mon Oct 13, 2008 8:04 am
Posts: 1
How can I get "year" value from date fied in HQL? to compare with?

public List<Disease> getDiseases(Integer year){
Query query = this.getSession().createQuery("SELECT d FROM Disease d WHERE year(d.date) = :year ");
query.setInteger("year", year);
return query.list();
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2008 10:34 pm 
Newbie

Joined: Fri Jul 14, 2006 12:05 pm
Posts: 19
Your best bet is probably going to be to change the query to select by date range:

Code:
Query query = this.getSession().createQuery("SELECT d FROM Disease d WHERE d.date between :startDate and :endDate");
query.setDate("startDate", <first day of year>);
query.setDate("endDate", <last day of year> );


(The date arithmetic is left as an exercise for the reader.)


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.