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.