-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem querying with CustomType in where clause
PostPosted: Fri Nov 21, 2003 4:40 am 
Newbie

Joined: Fri Oct 31, 2003 3:33 pm
Posts: 17
Location: California
All my persistent objects include an AuditInfo object (see http://hibernate.org/48.html). I'm trying to execute a query where the auditInfo create date is between two dates. I get a QueryException: dereferenced.

Here's the code:

Code:
   
     HibernateSession.currentSession().find(
        "from Customer c where c.auditInfo.created between ? and ? ",
        new Date[] { new GregorianCalendar( 2003, 11, 10 ).getTime(),
                           new GregorianCalendar( 2003, 11, 20 ).getTime() },
        new Type[] { Hibernate.TIMESTAMP, Hibernate.TIMESTAMP } ) ;


Here's the stack trace:

Code:
net.sf.hibernate.QueryException: dereferenced: item0_.auditInfo.created [from com.urbanauction.domain.Item i where i.auditInfo.created between ? and ? ]
   at net.sf.hibernate.hql.PathExpressionParser.token(PathExpressionParser.java:139)
   at net.sf.hibernate.hql.WhereParser.doPathExpression(WhereParser.java:333)
   at net.sf.hibernate.hql.WhereParser.doToken(WhereParser.java:365)
   at net.sf.hibernate.hql.WhereParser.token(WhereParser.java:250)
   at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
   at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
   at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
   at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:151)
   at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:140)
   at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:291)
   at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1501)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1472)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1462)
   at com.urbanauction.dao.WtfTest.testFoo(WtfTest.java:31)


Here's my mapping file:

Code:
<hibernate-mapping>

   <class name="com.urbanauction.domain.Item" table="ITEM">
      <id name="id" type="long" column="item_id">
         <generator class="assigned" />
      </id>

      <!-- Removed TONS of irrelevant properties and associations -->

      <property name="active"               column="active" />      

      <property name="auditInfo" type="net.wontonsoup.util.hibernate.AuditInfoType">
         <column name="updated"/>
         <column name="created"/>
         <column name="updated_by"/>
         <column name="created_by"/>
      </property>
                         
    </class>

</hibernate-mapping>


Any ideas? I'm probably just doing something stupid and/or didn't read part in the manual that says "You can't query custom types" or something. Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 4:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
use a CompositeUserType instead.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 5:07 pm 
Newbie

Joined: Fri Oct 31, 2003 3:33 pm
Posts: 17
Location: California
Thanks! From javadocs on CustomUserType:

Quote:
A UserType that may be dereferenced in a query. This interface allows a custom type to define "properties". These need not necessarily correspond to physical JavaBeans style properties.

A CompositeUserType may be used in almost every way that a component may be used. It may even contain many-to-one associations.


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

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.