0

I'm using hibernate for the data access layer,
so i have to write HQL query for the following SQL query.

select * from MyTable where my_date >= '16-SEP-2012'

It is working fine.. For this i have written HQL query as follows,

From MyTable as NB where NB.my_date >=date

It is throwing an error..

From MyTable as NB where NB.my_date >=Mon Mar 07 00:00:00 IST 1 org.hibernate.hql.ast.QuerySyntaxException: unexpected token: Mar

How to write HQL query for this.. Any Idea?

1 Answer 1

0

Try :date, since your current code is a syntax error. If it still doesn't work, try using a yyyy-MM-dd format - it might be a locale issue. Also be sure to set the parameter properly, you Did not include that part of your code.

Sign up to request clarification or add additional context in comments.

3 Comments

date of HQL is dynamic. So i just directly used it..What would be the syntax to execute it successfully?
Oh you concate strings? Then your date needs to be insides single quotes. I strongly recommend using proper parameters instead. Criteria api is a good alternative aswell for dynamic queries.
Be ware that constructing queries like that can potentially leave you open to sql injektion. Less so with jpa but still a very bad practice.

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.