*
The moose likes Object Relational Mapping and the fly likes hql query to get records of the week Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hql query to get records of the week" Watch "hql query to get records of the week" New topic
Author

hql query to get records of the week

krish bhadragiri
Greenhorn

Joined: Apr 17, 2007
Posts: 13
hi,
i want to retrieve records of the week (i.e records since last 7days).i wrote
"from WorkDetails as work_details where work_details.dated<=current_date and dated>=currrent_date-7 and work_details.employee_id="+employee_column_id"

but its throwingrg.hibernate.exception.SQLGrammarException:could not execute query.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

How do you set current_date? Should you not be using the current_date() function?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
krish bhadragiri
Greenhorn

Joined: Apr 17, 2007
Posts: 13
actually m setting the dates using string date format as '2007-04-19'in dated field of mysql table of colum type date.

so i want querries for retrieving records for last seven days and last 1 month.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

Since this is a Hibernate question, I'm moving it to our Object/Relational forum.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
David Madouros
Greenhorn

Joined: Mar 08, 2005
Posts: 18
This feels like more a hack than anything, but...

The problem is that mysql converts dates to numerics when you add or subtract. For example, current_date = 2007-04-20, but (current_date + 0) = 20070420. A solution (hack) for this is to do the following:



Ugly, but it works.


David Madouros<br />SCJP 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hql query to get records of the week
 
Similar Threads
Select Particular Column values in sql without know the column name
regarding MS access sql query
hql query to get records of the week
Design Pattern for Pagination in J2EE Application
hql query to get records of the week