-->
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.  [ 1 post ] 
Author Message
 Post subject: LazyInitializationException outer-join=true Criteria
PostPosted: Fri Feb 10, 2006 8:48 am 
Newbie

Joined: Wed Oct 06, 2004 4:39 pm
Posts: 17
Hi,

I have problem with Criteria.

My model is:
InventarioInicial have a set of Lote (lazy=true).
Lote have a set of Envase (lazy=true).
Lote have an many-to-one association with MateriaPrima (outer-join=true).
MateriaPrima have an many-to-one association with Ubicacion (outer-join=false).
Envase have an many-to-one association with Ubicacion (outer-join=true).

My mapping documents:

InventarioInicial
<set
name="lotes"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
column="id_inventarioinicial"
>
</key>
<one-to-many
class="ar.gov.ceride.inventorymgt.domain.Lote"
/>
</set>

Lote
<set
name="envases"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
column="id_lote"
>
</key>
<one-to-many
class="ar.gov.ceride.inventorymgt.domain.Envase"
/>
</set>
<many-to-one
name="materiaPrima"
class="ar.gov.ceride.inventorymgt.domain.MateriaPrima"
cascade="none"
outer-join="true"
update="true"
insert="true"
foreign-key="fk_lote_materiaprima"
>
<column
name="id_materiaprima"
not-null="true"
/>
</many-to-one>

MateriaPrima
<many-to-one
name="ubicacionPorDefecto"
class="ar.gov.ceride.inventorymgt.domain.Ubicacion"
cascade="none"
outer-join="false"
update="true"
insert="true"
foreign-key="fk_materiaprima_ubicacion"
>
<column
name="id_ubicacionpordefecto"
/>
</many-to-one>

Envase
<many-to-one
name="ubicacion"
class="ar.gov.ceride.inventorymgt.domain.Ubicacion"
cascade="none"
outer-join="true"
update="true"
insert="true"
foreign-key="fk_envase_ubicacion"
>
<column
name="id_ubicacion"
/>
</many-to-one>

The code that retrieve:
Criteria criteria = session.createCriteria(InventarioInicial.class);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
criteria.setFetchMode(criteria, "lotes",FetchMode.EAGER);
List list = criteria.list();
for (Iterator iter = list.iterator(); iter.hasNext();) {
InventarioInicial inventario = (InventarioInicial) iter.next();
for (Iterator it = inventario.getLotes().iterator(); it.hasNext();) {
Lote lote = (Lote) it.next();
Hibernate.initialize(lote.getEnvases());
}
}

The problem is:
The attribute ubicacion of Envase is not initialized, although the mapping is "outer-join=true". In the log, the sql to initialize the instances of Envase include an left outer join to Ubicacion, but the attribute is not initialized.
If I define the association many-to-one between MateriaPrima and Ubicacion with "outer-join=true", the problem is gone.

I am using Hibernate 2.1.8.

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.