Saturday, February 23, 2008

Hibernate's Solution for org.hibernate.hql.ast.QuerySyntaxException.

It take a more then 2 hours to me to solve this exception. I am sharing it with you guys so that new comers won't face it.

Suppose I have persistent object named 'User' mapped to Database table 'USER_DETAILS' in my User.hbm.xml file. When I tried to get object through HQL query ie
User user = session.createQuery("from User_Details where User_Id=1 ).uniqueResult();

I got " org.hibernate.hql.ast.QuerySyntaxExcepti
on: User_Details is not mapped [from User_Details where USER_ID=1".

Solution : I found that in HQL we have to supply persistent Object class name instead of DB table name in queries to retrieve object. i.e.
User user = session.createQuery("from User where User_Id=1 ).uniqueResult();

Regards

Mohit Agrawal

2 comments:

Tejas Patel said...

Thnx,it is very helpful to me.

certificateattestation20@gmail.com said...

Hi,
Great info. I like all your post. I will keep visiting this blog very often. It is good to see you verbalize from the heart and your clarity on this important subject can be easily observed.
Authentication Certificate