-->
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: help with HQL query
PostPosted: Wed Jul 19, 2006 10:35 pm 
Newbie

Joined: Thu Jun 15, 2006 5:58 pm
Posts: 18
Postgres 8.0 hibernate3.1.3
1. Need help with HQL query to display the date after 30 days from todays date ?.

2. If anyone knows a good link for HQL.could you please tell.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 10:55 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Looks like the postgres dialect doesn't have a dateadd function. Does postgres? If it does, and if you're willing to recompile your hibernate jar, you could registerFunction whatever the dateadd function postgres provides, then use it in HQL.

Have a look in PostgreSQLDialect.java. Add a registerFunction in where all the others are.

If postgres doesn't have a function that adds to dates, then there's not much you can do. You could use the year(), month() etc. functions, but there's a lot of work figuring out month and year changes, leap years, etc. Might as well just do it in java, it's easy enough with Calendar objects.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 11:13 pm 
Newbie

Joined: Thu Jun 15, 2006 5:58 pm
Posts: 18
(CURRENT DATE + (Integer + '30') )will add 30 days to the current date in postgres.

I have to retrieve all records from database with date less than (CURRENT DATE + (Integer + '30') ).

Is there a way to get this using HQL


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 11:39 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
current_date is in the dialect. Don't know about integer part, can you use "current_date + 30", omitting the single quotes and Integer thing?

You can see exactly what functions are already provided by the dialect by looking in the dialect file, org/hibernate/dialect/PostgreSQLDialect.java.

_________________
Code tags are your friend. Know them and use them.


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.