Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Query Exception

 
Swetha Gun
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When I try to exceute the following query, I get a query exception.

select a from Order_Item a where a.status=2

The Error I get is:
net.sf.hibernate.QueryException: in expected: a [select a from Order_Item a where a.status=2 ]
at net.sf.hibernate.hql.FromParser.token(FromParser.java:102)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:295)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1572)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:49)

Can anyone help me out with this?
Thanks.
 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you name the class as : "Order_Item" as this should be the name of the BEAN not the real table.

Just a guess.

Thanks,
Rahul
 
Reshma Shaik
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this query:
from Order_Item as item where item.status = 2;

Remember if your Order_Item class is in a package com.test.hib, then your will have to give the

from com.test.hib.Order_Item as item where item.status = 2;

i.e full package name.className shuld be given.
 
Swetha Gun
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply.
I tried both the ways neither of them worked.
When I used item, I got the same error, "in expected".

When I used the full package definition I got the following error:

"Undefined Alias Error."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic