-->
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: outer-join problem
PostPosted: Wed Jun 08, 2005 5:10 am 
Regular
Regular

Joined: Wed Sep 22, 2004 8:27 am
Posts: 89
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.05

Mapping documents:
<hibernate-mapping default-lazy="true">

<class name="com.coginfo.kf.bean.Modalita" table="KFT_MODALITA" select-before-update="true">
<meta attribute="class-description">Modalita</meta>
<composite-id name="id" class="com.coginfo.kf.bean.ModalitaPk">
<key-many-to-one name="codintdmn" class="com.coginfo.kf.bean.Dominio"/>
<key-property name="codint" length="10"/>
</composite-id>

<property name="cafdsc" type="string">
<column name="cafdsc" length="1000" sql-type="string" not-null="true"/>
</property>

<property name="codtip" type="integer">
<column name="codtip" length="1" sql-type="integer" not-null="true"/>
</property>

<many-to-one class="com.coginfo.kf.bean.ValoreModalita" name="codintvalmod" column="codintvalmod" fetch="join" lazy="true"/>

<set name="modalitaRuolo" lazy="true" cascade="none">
<key>
<column name="codintdmn"/>
<column name="codintmod"/>
</key>
<one-to-many class="com.coginfo.kf.bean.ModalitaRuolo"/>
</set>
</class>

<query name="find.modalita"><![CDATA[
from Modalita mod order by mod.cafdsc ]]>
</query>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
session.createCriteria(Modalita.class);

The generated SQL (show_sql=true):
1-
select modalita0_.codintdmn as codintdmn, modalita0_.codint as codint, modalita0_.cafdsc as cafdsc11_, modalita0_.codtip as codtip11_, modalita0_.codintvalmod as codintva5_11_ from KFT_MODALITA modalita0_

2-
select valoremoda0_.codint as codint0_, valoremoda0_.dscvalmod as dscvalmod13_0_, valoremoda0_.codtipmod as codtipmod13_0_ from KFT_VALORE_MODALITA valoremoda0_ where valoremoda0_.codint=?


The problem is: why 2 queries and not only 1 with outer-join??

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 5:43 am 
Newbie

Joined: Fri May 20, 2005 2:42 am
Posts: 14
Hello,

try the following :

1. remove the lazy="true" from the many-to-one tag.

if this does not work
2. set fetch mode explicitly in the criteria

session.createCriteria(Modalita.class).setFetchMode("codintvalmod", FetchMode.JOIN);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 7:05 am 
Regular
Regular

Joined: Wed Sep 22, 2004 8:27 am
Posts: 89
ok solve, thanks now other problem:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-lazy="false">

<class name="com.coginfo.kf.bean.Categoria" table="KFT_CATEGORIA" select-before-update="true">
<id name="codint" type="long" unsaved-value="0">
<generator class="sequence">
<param name="sequence">KF_SEQ_CATEGORIA</param>
</generator>
</id>

<property name="cafdsc" type="string">
<column name="cafdsc" length="1000" sql-type="string" not-null="true"/>
</property>

<set name="categoriaAclSviluppatori" where="stsacl = '2'" lazy="true" cascade="none">
<key column="codintctg"/>
<one-to-many class="com.coginfo.kf.bean.CategoriaAcl"/>
</set>

<set name="categoriaAclCollaudatori" where="stsacl = '3'" lazy="true" cascade="none" fetch="join">
<key column="codintctg"/>
<one-to-many class="com.coginfo.kf.bean.CategoriaAcl"/>
</set>

<set name="categoriaAclAmministratori" where="stsacl = '1'" lazy="true" cascade="none">
<key column="codintctg"/>
<one-to-many class="com.coginfo.kf.bean.CategoriaAcl"/>
</set>

<set name="categoriaRuoli" lazy="true" cascade="none">
<key column="codintctg"/>
<one-to-many class="com.coginfo.kf.bean.CategoriaRuolo"/>
</set>
</class>

<query name="find.categoria"><![CDATA[
from Categoria]]>
</query>

</hibernate-mapping>


when make session.createCriteria(Categoria.class).list()

hibernate generete this:

the first query is correct i.e: ... left outer join ...
but after this hibernate make a lot of:
select categoria0_.codint as codint1_, categoria0_.cafdsc as cafdsc6_1_, categoriaa1_.codintctg as codintctg3_, categoriaa1_.codintacl as codintacl3_, categoriaa1_.stsacl as stsacl3_, categoriaa1_.codintacl as codintacl0_, categoriaa1_.codintctg as codintctg0_, categoriaa1_.stsacl as stsacl0_ from KFT_CATEGORIA categoria0_ left outer join KFT_ACL_CATEGORIA categoriaa1_ on categoria0_.codint=categoriaa1_.codintctg and categoriaa1_.stsacl = '3' where categoria0_.codint=?

and finish with stackoverflow.


why? what's wrong? is it a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 8:09 am 
Newbie

Joined: Fri May 20, 2005 2:42 am
Posts: 14
a stackoverflow indicates an infinite loop of some kind, as far as my
exprience goes. you should try to remove one set after antoher to find
the set mapping that causes the problem (the loop). if you found the
set and thus the associated class, check the mapping of the associated
class.


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.