-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JPQL NamedQuery mapping problem
PostPosted: Sat Jul 07, 2007 11:18 am 
Newbie

Joined: Tue Nov 01, 2005 3:07 pm
Posts: 7
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.