-->
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: Specified join fetching, but owner not in select list.
PostPosted: Wed Mar 08, 2006 8:40 am 
Newbie

Joined: Thu Oct 14, 2004 10:05 am
Posts: 9
Location: Copenhagen, Denmark
After upgrading to Hibernate 3.1.2 from 3.0 some of our HQL queries fails with an exception saying that query specified join fetching, but the owner of the fetched association was not present in the select list

Can anyone tell me what this message means?
One of he failing queries is included below.

Kind regards
Claus Nielsen

Hibernate version:
3.1.2

(Partial) Mapping documents:

<class name="com.bmd.bs400.file.Kunde" table="KUNDEL1" lazy="true" >
<meta attribute="implement-equals">true</meta>
<meta attribute="extra-import" inherit="false">com.bmd.bs400.file.Abonnement</meta>

<id name="kundenr" column="AJAENB" type="com.bmd.bs400.hibernate.KundenrUserType">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
<generator class="assigned"/>
</id>

<component name="adresse" class="com.bmd.bs400.component.Adresse">
<property name="fornavn" column="AJP1TE" type="com.bmd.bs400.hibernate.FornavnUserType">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</property>
<property name="efternavn" column="AJP2TE" type="com.bmd.bs400.hibernate.EfternavnUserType">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</property>
<property name="extraNavn" column="AJAEA3" type="com.bmd.bs400.hibernate.ExtraNavnUserType">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</property>
<property name="gadeAdresse" column="AJADA3" type="com.bmd.bs400.hibernate.GadeAdresseUserType">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</property>
<property name="stednavn" column="AJAFA3" type="com.bmd.bs400.hibernate.StednavnUserType">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</property>
<many-to-one name="postnummer" class="com.bmd.bs400.file.Postnummer" insert="false" update="false">
<column name="AJAXCD" />
<column name="AJAICD" />
</many-to-one>
<property name="postnr" column="AJAICD" type="com.bmd.bs400.hibernate.PostnrUserType">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</property>
<property name="landekode" column="AJAXCD" type="com.bmd.bs400.hibernate.LandekodeUserType">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</property>
</component>
</class>


<class name="com.bmd.bs400.file.Postnummer" table="POSTN2L2" lazy="true" >
<meta attribute="implement-equals">true</meta>

<composite-id name="postnummerPK" class="com.bmd.bs400.file.PostnummerPK">
<key-property name="landekode" column="ATAXCD"
type="com.bmd.bs400.hibernate.LandekodeUserType">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</key-property>
<key-property name="postnr" column="ATAICD"
type="com.bmd.bs400.hibernate.PostnrUserType">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</key-property>
</composite-id>

<many-to-one name="land" class="com.bmd.bs400.file.Land"
insert="false" update="false">
<meta attribute="use-in-equals">false</meta>
<meta attribute="use-in-tostring">false</meta>
<column name="ATAXCD" />
</many-to-one>

<property name="postdistrikt" column="ATABA3"
type="com.bmd.bs400.hibernate.PostdistriktUserType">
</property>

</class>


<class name="com.bmd.bs400.file.Land" table="LANDL3" lazy="true">
<meta attribute="implement-equals">true</meta>

<id name="landekode" column="BOAXCD" type="com.bmd.bs400.hibernate.LandekodeUserType">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
<generator class="assigned" />
</id>

<property name="landenavn" column="BOAAA3"
type="com.bmd.bs400.hibernate.LandenavnUserType">
</property>

</class>



Code between sessionFactory.openSession() and session.close():
Object[] result = (Object[]) template.execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query = session.createQuery(
"select k.adresse.fornavn, k.adresse.efternavn, k.adresse.extraNavn"
+ ", k.adresse.gadeAdresse, k.adresse.stednavn"
+ ", pn.postnummerPK.postnr, pn.postdistrikt"
+ ", land.landekode, land.landenavn"
+ " from Kunde k"
+ " left outer join fetch k.adresse.postnummer pn"
+ " left outer join fetch k.adresse.postnummer.land land"
+ " where k.kundenr = :kundenr"
+ " order by k.kundenr ");
query.setParameter("kundenr", kundenr, type(KundenrUserType.class));
return query.uniqueResult();
}
});

Full stack trace of any exception that occurs:
org.springframework.orm.hibernate3.HibernateQueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=pn,role=null,tableName=POSTN2L2,tableAlias=postnummer1_,origin=KUNDEL1 kunde0_,colums={kunde0_.AJAXCD kunde0_.AJAICD ,className=com.bmd.bs400.file.Postnummer}}] [select k.adresse.fornavn, k.adresse.efternavn, k.adresse.extraNavn, k.adresse.gadeAdresse, k.adresse.stednavn, pn.postnummerPK.postnr, pn.postdistrikt, land.landekode, land.landenavn from com.bmd.bs400.file.Kunde k left outer join fetch k.adresse.postnummer pn left outer join fetch k.adresse.postnummer.land land where k.kundenr = :kundenr order by k.kundenr ]; nested exception is org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=pn,role=null,tableName=POSTN2L2,tableAlias=postnummer1_,origin=KUNDEL1 kunde0_,colums={kunde0_.AJAXCD kunde0_.AJAICD ,className=com.bmd.bs400.file.Postnummer}}] [select k.adresse.fornavn, k.adresse.efternavn, k.adresse.extraNavn, k.adresse.gadeAdresse, k.adresse.stednavn, pn.postnummerPK.postnr, pn.postdistrikt, land.landekode, land.landenavn from com.bmd.bs400.file.Kunde k left outer join fetch k.adresse.postnummer pn left outer join fetch k.adresse.postnummer.land land where k.kundenr = :kundenr order by k.kundenr ]
org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=pn,role=null,tableName=POSTN2L2,tableAlias=postnummer1_,origin=KUNDEL1 kunde0_,colums={kunde0_.AJAXCD kunde0_.AJAICD ,className=com.bmd.bs400.file.Postnummer}}] [select k.adresse.fornavn, k.adresse.efternavn, k.adresse.extraNavn, k.adresse.gadeAdresse, k.adresse.stednavn, pn.postnummerPK.postnr, pn.postdistrikt, land.landekode, land.landenavn from com.bmd.bs400.file.Kunde k left outer join fetch k.adresse.postnummer pn left outer join fetch k.adresse.postnummer.land land where k.kundenr = :kundenr order by k.kundenr ]
at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:190)
at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:637)
at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:466)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:645)
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:218)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:134)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:113)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1602)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.orm.hibernate3.HibernateTemplate$CloseSuppressingInvocationHandler.invoke(HibernateTemplate.java:1183)
at $Proxy32.createQuery(Unknown Source)
at com.bmd.bs400.dao.SelfServiceDaoImpl$1.doInHibernate(SelfServiceDaoImpl.java:164)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:334)
at com.bmd.bs400.dao.SelfServiceDaoImpl.hentKundeoplysninger(SelfServiceDaoImpl.java:162)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at com.bmd.dao.interceptor.AbstractSchemaSelector.invoke(AbstractSchemaSelector.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy29.hentKundeoplysninger(Unknown Source)
at com.bmd.bs400.dao.SelfServiceDaoTest.testRetKundeoplysninger_validering(SelfServiceDaoTest.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


Name and version of the database you are using:
DB2/400 (driver is JTOpen 5.0)

The generated SQL (show_sql=true):
n/a

Debug level Hibernate log excerpt:


Last edited by clanie on Thu Mar 09, 2006 7:25 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 11:54 am 
Beginner
Beginner

Joined: Mon Mar 14, 2005 6:07 pm
Posts: 36
I think there may be an open bug for this one, scheduled for 3.1.2:

http://opensource2.atlassian.com/projec ... e/HHH-1306


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 4:03 am 
Newbie

Joined: Thu Oct 14, 2004 10:05 am
Posts: 9
Location: Copenhagen, Denmark
No, that isn't it.

It still fails with 3.1.2 (actually I've been using 3.1.2 all along - just wrote the wrong version number in my initial post).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 7:35 am 
Newbie

Joined: Thu Oct 14, 2004 10:05 am
Posts: 9
Location: Copenhagen, Denmark
I got the query working again by removing the joins.

This is the original query:

"select k.adresse.fornavn, k.adresse.efternavn, k.adresse.extraNavn"
+ ", k.adresse.gadeAdresse, k.adresse.stednavn"
+ ", pn.postnummerPK.postnr, pn.postdistrikt"
+ ", land.landekode, land.landenavn"
+ " from Kunde k"
+ " left outer join fetch k.adresse.postnummer pn"
+ " left outer join fetch k.adresse.postnummer.land land"
+ " where k.kundenr = :kundenr"
+ " order by k.kundenr ");

It now looks like this:
"select k.adresse.fornavn, k.adresse.efternavn, k.adresse.extraNavn"
+ ", k.adresse.gadeAdresse, k.adresse.stednavn"
+ ", k.adresse.postnr, k.adresse.postnummer.postdistrikt"
+ ", k.adresse.landekode, k.adresse.postnummer.land.landenavn"
+ " from Kunde k"
+ " where k.kundenr = :kundenr"
+ " order by k.kundenr ");

Since only one field from each of the join-files is used the change actually makes the query shorter and it is also just as readable as the original, but I have other cases where more fields are involved, and they certainly gets harder to read if I change them like this.

Can anyone see any reason why the original query shouldn't work?
Can it have something to do with the associations being part of the adresse component of Kunde?


Top
 Profile  
 
 Post subject: Solved!
PostPosted: Thu Mar 09, 2006 8:44 am 
Newbie

Joined: Thu Oct 14, 2004 10:05 am
Posts: 9
Location: Copenhagen, Denmark
I finally figured it out.

According to the Hibernate docs "a "fetch" join allows associations or collections of values to be initialized along with their parent objects".

That is of course not possible, since "addresse" isn't one of the selected fields, so the exception is completely right.

I don't know why the "fetch" was there in the first place. It shouldn't be, and after deleting it the query works again.

3.0 apparantly just ignored it. 3.1 is more picky - but right.


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.