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.
|