Wednesday, 27 October 2010

@Entity(name != table_name !!!

Normally if you get "org.hibernate.hql.ast.QuerySyntaxException: is not mapped" then you used the table name in stead of the class name. In my case I'm ashamed to admit, 
I though setting @Entity(name is setting the table name,
where in fact it is setting the JPQL alias! 
I thought it was weird that you can set that and the @Table(name . 


@Entity(name != table_name !!!
@Entity(name != table_name !!!
@Entity(name != table_name !!!
@Entity(name != table_name !!!
@Entity(name != table_name !!!
@Entity(name != table_name !!!
@Entity(name != table_name !!!
@Entity(name != table_name !!!
@Entity(name != table_name !!!
@Entity(name != table_name !!!


Thanks Matt Raible for showing me the light:

If you specify a name value for your @Entity annotation (for example
@Entity(name="person")), this will be the alias for HQL queries. If you
don't specify this value, the name will match the short name of your class (
Person). If you want to change the table name that's generated, use the
@Table
with a "name" value.

No comments:

Post a comment