1

My query below, shows hibernate exception:

SELECT DATE_ADD(DATE_FORMAT(MIN(t.time),'%Y-%m-%d'), INTERVAL 6 DAY) FROM Table t;

From what I understand, hibernate doesn't recognize INTERVAL keyword.

Can anyone please help me write an HQL query which gives me the same result as my above query?

(I am trying to get the date post 1 week from the minimum date in my table)

1 Answer 1

1

HQL and SQL are two different things. You could use a native SQL query instead of a HQL query. Or you could just execute the following query:

select min(t.time) from SomeEntity e

and add 6 days in Java:

Date minDate = (Date) query.uniqueResult();
minDate = DateUtils.addDays(d, 6); // using apache commons-lang
Sign up to request clarification or add additional context in comments.

2 Comments

I need the result inside my query, because i am using it as a sub-query. I am trying to find some cumulative value of a row in my table only for the first week. So, inside my query there are condition like: date >= min(date) and date <= (a date after 6 days from the min(date))
Then I'm afraid you'll need to use SQL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.