-->
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.  [ 6 posts ] 
Author Message
 Post subject: EJB-QL + collection properties bug
PostPosted: Mon Oct 24, 2005 5:51 pm 
Newbie

Joined: Tue Jul 12, 2005 1:17 pm
Posts: 7
Hi,

We are trying to upgrade from Hibernate-3.1alpha to Hibernate-3.1rc2 (along with the entitymanager and annotation features). We are entirely EJB3 based and some of our queries have stopped working that used to work. For instance, we have a query like this:

SELECT c FROM Change c WHERE c.moduleList.project.id = 23

This would normally show all changes in project id=23. In this case, Change has a 1 to Many relationship with Module through the moduleList property which has a 1 to 1 with Project. Here is the result of running that query in the current release:

Oct 24, 2005 2:48:22 PM org.hibernate.hql.ast.ErrorCounter reportError
SEVERE: illegal syntax near collection: project
java.lang.NullPointerException
at org.hibernate.hql.ast.tree.DotNode.getColumns(DotNode.java:97)
at org.hibernate.hql.ast.tree.DotNode.initText(DotNode.java:210)
at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:204)
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:626)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1215)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4024)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3510)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1758)
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:216)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:156)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:103)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:473)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1060)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1010)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:38)
at gsc.report.EJBUtil.getList(EJBUtil.java:83)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 5:54 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The proper way is to do
SELECT c FROM Change c join c.moduleList module WHERE module.project.id = 23

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Regression
PostPosted: Wed Oct 26, 2005 7:28 pm 
Newbie

Joined: Tue Jul 12, 2005 1:17 pm
Posts: 7
So you're saying that the old behavior was a bug and that I need to update my queries? Thats ok, but this is still a bug as I shouldn't be getting an NPE. Further, I think that the old syntax that we were using was easier and better. Can you point me to the place in the EJB specification that describes this situation and defines the correct behavior?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 27, 2005 6:10 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
AFAIK, a dotted notation after a collection is not part of the EJBQL grammar (not the HQL one).
Actually the NPE is explained in the severe comment
SEVERE: illegal syntax near collection: project

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Differnet is the 'moduleList' is mapped as a compsite-eleme?
PostPosted: Mon Mar 13, 2006 12:45 pm 
Newbie

Joined: Mon Apr 19, 2004 3:24 pm
Posts: 9
Is this still true if the 'moduleList' property is mapped as a composite-element? In the example mapping below 'contents' is my equivalent to 'moduleList'. It's declared on an object called CurveSet.

e.g:

<class name="CurveSet" table="CURVE_SET" dynamic-update="true" select-before-update="true">
<id name="id" column="id" unsaved-value="0" type="long">
<generator class="sequence">
<param name="sequence">CURVE_SET_SEQ</param>
</generator>
</id>
<version name="version" type="long"/>

<property name="name" type="string"/>
<property name="created" type="timestamp" column="CREATEDDATE" access="com.rbsfm.ice.common.persist.DateTimeAccessor"/>
<property name="updated" type="timestamp" column="UPDATEDDATE" access="com.rbsfm.ice.common.persist.DateTimeAccessor"/>
<property name="isLocked" column="LOCK_FLAG" type="yes_no"/>
<property name="isPublic" column="PUBLIC_FLAG" type="yes_no"/>

<many-to-one name="owner" column="PERS_ID" lazy="false"/>

<set name="contents" table="CURVE_SET_MEMBERSHIP" batch-size="100" access="field" cascade="all,delete-orphan">
<key column="CUSE_ID"/>
<composite-element class="CurveSetMembership">
<parent name="curveSet"/>
<property name="updated" column="UPDATEDDATE" type="timestamp" access="com.rbsfm.ice.common.persist.DateTimeAccessor"/>
<many-to-one name="curve" column="CURV_ID" not-null="true" access="field" cascade="save-update, merge"/>
</composite-element>
</set>
</class>

In this case my query might be "from CurveSet c where c.contents.curve.id=:someValue"

I've tried using "from CurveSet c join c.contents con where con.curve.id=:someValue"
In the second case, where 'contents' is mapped as above, I get an exception:

org.hibernate.QueryException: could not resolve property: curve.id of: com.rbsfm.ice.marketdata.domain.CurveSet [select new com.rbsfm.ice.marketdata.view.CurveSummary(c.name, c.id, c.version, c.curveType, c.referenceEntity, size(cc)) from com.rbsfm.ice.marketdata.domain.Curve c left outer join c.referenceEntity left outer join c.children cc, com.rbsfm.ice.marketdata.domain.CurveSet cs join cs.contents csm where csm.curve.id=c.id and cs.id=:curveSetId group by c.name, c.curveType, c.referenceEntity.id, c.version, c.id]

It's as though hibernate thinks that my 'csm' alias is a CurveSet, and not a CurveSetMembership object.

Is this a bug or am I querying incorrectly?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 8:52 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If you have
Code:
from CurveSet c join c.contents con where con.curve.id=:someValue

Then open a bug with the minimal mapping to reproduce

But your query (as shown in the exception) is very different

_________________
Emmanuel


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