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 t.name = ?];
nested exception is org.hibernate.hql.ast.QuerySyntaxException:
Test is not mapped [from Test t where t.name = ?] at
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:640)


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

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

11 comments:

Unknown 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 :)

Unknown said...

Thanks for gr8 help indeed.

Anonymous said...

Thanks :)

Unknown 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:


@Entity
@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.

http://fundapass.blogspot.in/2012/09/xyz-is-not-mapped-from-xyz.html

Anonymous said...

Thanks !!!!