Reputation: 287
this should be easy, but my app throws constant error, and I'm new to Hibernate.
I am trying to have simple HQL query in my web app using Hibernate.
I want to execute the following SQL query:
SELECT * FROM deal WHERE deal_status='A' OR WHERE deal_status='O';
HQL does not seem to work with or clause, here my current HQL statements in my web app:
FROM deal d where d.deal_status='O' or d.deal_status='A' order by d.id
Thanks for any Hibernate query help
Regards Alex
Upvotes: 1
Views: 8927
Reputation: 120791
c.id
- c is not definedI strongly assume that the fields in Deal (Classname first letter upper case) are not deal_status
but status, then the query must be like this. (I skipped the c.id stuff, because I have no idea what you mean by this.)
SELECT d FROM Deal d WHERE d.status='O' or d.status=`A`
Notice the upper D from Deal
And this will only work if Deal.status is a String or something like that, but not if it is a Enum. One way to handle an Enum is this:
Query query = session.createQuery(
"SELECT d FROM Deal d WHERE d.status=:o or d.status=:a");
query.setParameter("a", MyEnum.A);
query.setParameter("o", MyEnum.O);
Upvotes: 3