This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma 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

hql query to get records of the week

krish bhadragiri

Joined: Apr 17, 2007
Posts: 13
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

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

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

Joined: May 26, 2003
Posts: 32481

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

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
David Madouros

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: hql query to get records of the week
It's not a secret anymore!