Hi,
I'm a newcomer to ORM and am switching from Toplink Essentials to Hibernate.
My named query (which worked fine in Toplink) won't run on Hibernate. It throws the following exception:
2007-07-07 18:03:58,906 4719 [ main] ERROR ernate.impl.SessionFactoryImpl - Error in named query: myQuery
org.hibernate.QueryException: could not resolve property: myDate of: MyMappedClass [SELECT o FROM MyMappedClass o WHERE o.myDate = :target_date]
at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1310)
at org.hibernate.hql.ast.tree.FromElementType.getPropertyType(FromElementType.java:280)
[...]
I'm using annotations to map the colums to the table (which work in TopLink):
Code:
@Entity
@Table(name="MY_TABLE")
@NamedQuery(
name="myQuery",
query="SELECT o FROM MyMappedClass o WHERE o.myDate = :target_date")
public class MyMappedClass implements Serializable {
@Id
@Column(name="MY_DATE")
private Date myDate;
}
I noticed (from the exception stack trace) that hibernate uses the HQL parser, even though I want to use JPQL. I thus changed the query to use HQL syntax, which works, but I have to use the table column name instead of the class field name, as HQL ignores the @Column mapping:
Code:
@NamedQuery(
name="myQuery",
query="FROM MyMappedClass WHERE my_Date = :target_date")
Notice how I have to use the underscore in my_Date (otherwise the HQL version fails with the same exception).
I tried adding the underscore to the JPQL version and that still won't work. What's wrong with my query and its mapping?