Saturday, 5 April 2008

hibernate3 - hibernateQueryException - Class is not mapped

I have been having a problem for a while trying to get a basic hibernate3 and Spring 2.5 example working. Using old style hibernate CLASS_NAME.hbm.xml files worked fine. When I changed the context.xml file to try & use annotations instead I got the following error:

Exception in thread "main" org.springframework.orm.hibernate3.HibernateQueryException:
Test is not mapped [from Test t where = ?];
nested exception is org.hibernate.hql.ast.QuerySyntaxException:
Test is not mapped [from Test t where = ?] at

Check the imports of your '@Entity' annotations in your beans

If it is:
Then change it to:
    import javax.persistence.Entity;
and life will be sweet.


just_do_it said...

thank you, man!

spip said...

... thank you ! *EXACTLY* what I was looking for ... dammn glad your post came in the first hits in my googling...

Anonymous said...

thanks :)

Ahsan Afreen said...

Thanks for gr8 help indeed.

Anonymous said...

Thanks :)

Anderson said...

excellent, my problems is IMPORT

Juan Manuel Formoso said...

Hi, this didn't work for me, exactly the same error with import javax.persistence.Entity;

Anonymous said...

@Juan Manuel Formoso: I had the same error with import javax.persistence.Entity too, it turned out to be the lack of @Table annotation in my entity. Like this:

@Table(name="table_name") // without this annotation it throws QuerySyntaxException: Table is not mapped
public class Table {
// class body

Nitz said...

sigh of relief... small thing but hard to catch. :)

Sayan Guharoy said...

I came here seeking solution for
XYZ is not mapped[FROM XYZ ] hibernate exception.

I got it resolved by using full java class path instead of table name.I though it might be helpful somebody else also.Please look below for full description.

Anonymous said...

Thanks !!!!