-->
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.  [ 4 posts ] 
Author Message
 Post subject: QueryException: "dereferenced" while retrieving a
PostPosted: Wed Feb 09, 2005 10:41 pm 
Newbie

Joined: Sun Dec 28, 2003 2:07 pm
Posts: 15
Location: Quebec, Canada
Hi, I'm wondering how to order my result set when I am mapping a UserType. I am using a variation of the Null Object pattern to save/load times that evaluate to "the future".

So, to do that, I mapped my time using two columns: propertyName_is_future and propertyName_datetime. Now, I'd like to retrieve my objects ordered by descending datetime. I get a QueryException, detailed below.

First of all, is that even possible ? Second, if so, how ? Third, anyone has a simple solution ? I also need to use setMaxResults() to only retrieve the first few entries of the ordered set.

Thanks for any tips !
François


Hibernate version:
2.1.7

Mapping documents:
Code:
<property name="postedOn"
    type="com.careernudge.dao.hibernate.type.InstantType">
    <column name="postedOn_is_future" sql-type="bit"/>
    <column name="postedOn_datetime" sql-type="datetime"/>
</property>


InstantType class excerpt:
Code:
public Object nullSafeGet(ResultSet rs, String[] columnNames,
                          Object command) throws HibernateException,
        SQLException {
    boolean future = rs.getBoolean(columnNames[0]);
    if (rs.wasNull()) {
        return null;
    } else if (future) {
        return FutureInstant.SOLE_INSTANCE;
    }

    Date instant = rs.getDate(columnNames[1]);
    return new Instant(instant);
}


Instant is part of Joda Time. I'm using v0.98 of Joda Time.

Code between sessionFactory.openSession() and session.close():
Code:
Query q = session.createQuery(
        "from HibernateBlogEntry e " +
        "order by e.postedOn.datetime desc");
q.setMaxResults(numberOfEntries);
return q.list();


Second query attempt
I also tried the following query, but then I get a different exception:
Code:
Query q = session.createQuery(
        "from HibernateBlogEntry e " +
        "order by e.postedOn desc");
q.setMaxResults(numberOfEntries);
return q.list();

Code:
2005-02-09 21:27:39 StandardWrapperValve[careernudge]: Servlet.service() for servlet careernudge threw exception
org.springframework.orm.hibernate.HibernateQueryException: path expression ends in a composite value: hibernateb0_.postedOn [from com.careernudge.dao.hibernate.HibernateBlogEntry e order by e.postedOn desc]; nested exception is net.sf.hibernate.QueryException: path expression ends in a composite value: hibernateb0_.postedOn [from com.careernudge.dao.hibernate.HibernateBlogEntry e order by e.postedOn desc]
net.sf.hibernate.QueryException: path expression ends in a composite value: hibernateb0_.postedOn [from com.careernudge.dao.hibernate.HibernateBlogEntry e order by e.postedOn desc]
   at net.sf.hibernate.hql.PathExpressionParser.getWhereColumn(PathExpressionParser.java:375)
   at net.sf.hibernate.hql.OrderByParser.token(OrderByParser.java:31)
   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:149)
   at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
   at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:295)
   at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1571)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1542)
   at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
   at com.careernudge.dao.hibernate.HibernateBlogDao$1.doInHibernate(HibernateBlogDao.java:26)
   at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:200)
   at org.springframework.orm.hibernate.HibernateTemplate.executeFind(HibernateTemplate.java:220)
   at com.careernudge.dao.hibernate.HibernateBlogDao.findMostRecentEntries(HibernateBlogDao.java:18)


Full stack trace of any exception that occurs:
Code:
2005-02-09 21:10:51 StandardWrapperValve[careernudge]: Servlet.service() for servlet careernudge threw exception
org.springframework.orm.hibernate.HibernateQueryException: dereferenced: hibernateb0_.postedOn.datetime [from com.careernudge.dao.hibernate.HibernateBlogEntry e order by e.postedOn.datetime desc]; nested exception is net.sf.hibernate.QueryException: dereferenced: hibernateb0_.postedOn.datetime [from com.careernudge.dao.hibernate.HibernateBlogEntry e order by e.postedOn.datetime desc]
net.sf.hibernate.QueryException: dereferenced: hibernateb0_.postedOn.datetime [from com.careernudge.dao.hibernate.HibernateBlogEntry e order by e.postedOn.datetime desc]
   at net.sf.hibernate.hql.PathExpressionParser.token(PathExpressionParser.java:140)
   at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
   at net.sf.hibernate.hql.OrderByParser.token(OrderByParser.java:30)
   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:149)
   at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
   at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:295)
   at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1571)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1542)
   at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
   at com.careernudge.dao.hibernate.HibernateBlogDao$1.doInHibernate(HibernateBlogDao.java:26)
   at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:200)
   at org.springframework.orm.hibernate.HibernateTemplate.executeFind(HibernateTemplate.java:220)
   at com.careernudge.dao.hibernate.HibernateBlogDao.findMostRecentEntries(HibernateBlogDao.java:18)
   at com.careernudge.web.filters.RecentBlogEntriesFinderFilter.doFilter(RecentBlogEntriesFinderFilter.java:29)


Name and version of the database you are using:
HSQLDB 1.7.3.2

The generated SQL (show_sql=true):
None, that's why I'm asking :)

Debug level Hibernate log excerpt:
Code:
2005-02-09 21:20:21,734 [DEBUG] impl.SessionImpl               - opened session
2005-02-09 21:20:21,750 [DEBUG] impl.SessionImpl               - find: from HibernateBlogEntry e order by e.postedOn.datetime desc
2005-02-09 21:20:21,765 [DEBUG] engine.QueryParameters         - named parameters: {}
2005-02-09 21:20:21,781 [DEBUG] hql.QueryTranslator            - compiling query
2005-02-09 21:20:21,796 [DEBUG] impl.SessionImpl               - closing session
2005-02-09 21:20:21,796 [DEBUG] impl.SessionImpl               - running Session.finalize()


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 09, 2005 10:49 pm 
Hibernate Team
Hibernate Team

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 09, 2005 11:38 pm 
Newbie

Joined: Sun Dec 28, 2003 2:07 pm
Posts: 15
Location: Quebec, Canada
Hello Gavin.

Thanks for the quick reply. I implemented a CompositeUserType instead, and things are rolling again.

The only issue remaining is this: isMutable() returns false. What should I do with setProperty() ? Throw an exception ? Accept the value ?

Thanks !
François


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 12:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Um, I forget ;-)

Exception I think.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.