This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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


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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30580
    
154

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
 
GeeCON Prague 2014
 
subject: hql query to get records of the week