-->
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.  [ 5 posts ] 
Author Message
 Post subject: Regression with Hibernate 3.2.3-GA
PostPosted: Tue Apr 03, 2007 10:08 am 
Newbie

Joined: Thu Apr 21, 2005 4:59 am
Posts: 15
I tried latest Hibernate release : 3.2.3 GA but I had to switch back to previous version quickly.

I got the following error, but the query runs perfectly on version 3.2.2 :
Code:
org.hibernate.QueryException: illegal attempt to dereference collection [psegmentdo2_.ID.customerSegments] with element property reference [segmentationId] [ select distinct ct from com.openpricer.common.is.PCustomerEnterprise ce, com.openpricer.ac.Segmentation.is.PCustomerSegment cs, com.openpricer.common.is.PSegmentDocument ct where cs.structureId=ct.customerSegments.segmentationId and (cs.segId=ct.customerSegments.segmentId or ct.customerSegments.segmentId = ? ) and cs.objId=ce.internalID and ce.internalID = ? ]
        at org.hibernate.hql.ast.tree.DotNode$1.buildIllegalCollectionDereferenceException(DotNode.java:46)
        at org.hibernate.hql.ast.tree.DotNode.checkLhsIsNotCollection(DotNode.java:512)
        at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:221)
        at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:94)
        at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:90)
        at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:728)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1216)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4041)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3528)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1762)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1687)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1687)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1687)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
        at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
        at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
        at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
        at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
        at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
        at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
        at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
        at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)


Top
 Profile  
 
 Post subject: Same Problem Here: illegal attempt to dereference collection
PostPosted: Tue Apr 03, 2007 6:12 pm 
Newbie

Joined: Mon Sep 08, 2003 4:04 pm
Posts: 8
Location: San Diego, CA
Same exact problem here. I get the same exception when executing a Query.

I have objects mapped like this:
Code:
<class name="myclass.beans.Event" table="events">
   <composite-id>
      <key-many-to-one name="meeting" class="myclass.beans.Meeting">
         <column name="day"/>
         <column name="meeting_number"/>
      </key-many-to-one>
      <key-property name="eventNumber" column="event_number"/>
   </composite-id>
</class>
<class name="myclass.beans.Meeting" table="meetings">
   <composite-id>
      <key-property name="day" column="day"/>
      <key-many-to-one name="map" class="myclass.beans.Map" column="meeting_number"/>
   </composite-id>
</class>
<class name="myclass.beans.Map" table="track_map">
   <id name="meetingNumber" column="meeting_number" type="int">
      <generator class="assigned"/>
   </id>
   <set name="associationAlias" inverse="true" cascade="delete" order-by="association_name" batch-size="10">
      <key column="meeting_number"/>
      <one-to-many class="myclass.beans.AssociationAlias"/>
   </set>
</class>
<class name="myclass.beans.AssociationAlias" table="association_alias">
   <composite-id>
      <key-many-to-one name="trackMap" class="myclass.beans.Map" column="meeting_number"/>
      <key-property name="associationName" column="association_name"/>
   </composite-id>
</class>


Then execute a query like this:

Code:
Query q = sess.createQuery("from Event e where e.meeting.day = :day"
   + " and e.meeting.map.associationAlias.code = :name"
   + " and e.eventNumber = :eventNumber");
q.setDate("day", date);
q.setString("name", name);
q.setInteger("eventNumber", eventNumber);
return q.list(); // <--- Throws QueryException


Throws this QueryException using 3.2.3 (but runs just fine using 3.2.2):
Code:
org.hibernate.QueryException: illegal attempt to dereference collection  [(event0_.day, event0_.meeting_number, event0_.event_number)(event0_.day, event0_.meeting_number)meetingmeetin1_.meeting_numbermap.associationAlias] with element property reference [associationName] [from myclass.beans.Event e where e.meeting.raceday = :raceday and e.meeting.map.associationAlias.associationName = :name and e.eventNumber = :eventNumber]

   at org.hibernate.hql.ast.tree.DotNode$1.buildIllegalCollectionDereferenceException(DotNode.java:46)
   at org.hibernate.hql.ast.tree.DotNode.checkLhsIsNotCollection(DotNode.java:512)
   at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:221)
   at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:94)
   at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:90)
   at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:728)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1216)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4041)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3525)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1762)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1690)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1687)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
   at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
   at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
   at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
   at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
   at myclass.util.HibernateUtil.getEventByAssociationName(HibernateUtil.java:1469)


Last edited by drees on Tue Apr 03, 2007 6:21 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 6:19 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The expression alias.collectionName.propertyName was never a supported path identifier, if it worked at all, it worked by accident. You will not find any example showing such a syntax, in fact, you will find documentation that says "don't do it". Use an explicit join to assign another alias to the collection.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 6:35 pm 
Newbie

Joined: Mon Sep 08, 2003 4:04 pm
Posts: 8
Location: San Diego, CA
Thank you, very helpful. I have changed my query to this and it appears to work with 3.2.3 now:

Code:
Query q = sess.createQuery("select e from Event e join e.meeting as m"
         + " join m.map as m2 join m2.associationAlias as aa"
         + " where m.raceday = :raceday"
         + " and aa.associationName = :name"
         + " and e.eventNumber = :eventNumber");


Edit: I realize that this also works (just joining the collection as Christian suggests which is perhaps a bit more readable):

Code:
Query q = sess.createQuery("select e from Event e"
         + " join e.meeting.map.associationAlias as aa"
         + " where e.meeting.raceday = :raceday"
         + " and aa.associationName) = :name"
         + " and e.eventNumber = :eventNumber");


Hopefully my examples will help the original poster.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 9:25 am 
Newbie

Joined: Wed May 23, 2007 9:17 am
Posts: 1
christian wrote:
The expression alias.collectionName.propertyName was never a supported path identifier, if it worked at all, it worked by accident. You will not find any example showing such a syntax, in fact, you will find documentation that says "don't do it". Use an explicit join to assign another alias to the collection.


If this only worked by accident why is there an example with such a expression in your hibernate book? In section 14.3.1 on page 654 there is a example that looks like this:

Code:
from Bid b where b.item.id = 1


Or is there another solution to access a linked table with a foreign key without joining the source table?


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