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
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply 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: 23628

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]
Certs: SCEA Part 1, Part 2 & 3 & Core Spring 3, OCAJP
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
 
 
subject: hql query to get records of the week
 
Threads others viewed
Select Particular Column values in sql without know the column name
hql query to get records of the week
regarding MS access sql query
Design Pattern for Pagination in J2EE Application
hql query to get records of the week
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture