-->
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: How to fetch all lazy properties!?
PostPosted: Thu Feb 16, 2006 1:30 pm 
Newbie

Joined: Wed Feb 15, 2006 3:13 pm
Posts: 5
Hi. I'm need to fetch all lazy properties of my Object. I've tryied "fetch all properties", ive tryied it with criteria and setResultTransformer.

With fetch all properties, my set named partesContrarias is not loaded.
With Criteria and setFetchMode and setResultTrasfomer (as you can see below) the items in my list get duplicated!! Thanks in advance!!

Hibernate version: 3.0.5

Mapping documents:

<?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 package="br.com.sapiensit.sigterra.administrativo.model.bo" default-lazy="true">

<class name="PastaProcessoBO" table="TB_PASTA_PROCESSO">
<id name="id" type="long" column="ID">
<generator class="sequence">
<param name="sequence">SQ_PASTA_PROCESSO</param>
</generator>
</id>

<property name="nrPasta" column="NR_PASTA" not-null="true"/>
<property name="nrProcesso" column="NR_PROCESSO" not-null="true"/>
<property name="dtAno" column="DT_ANO" not-null="false"/>
<property name="dsObjeto" column="DS_OBJETO" not-null="true"/>
<property name="dtAjuizamento" column="DT_AJUIZAMENTO" not-null="true"/>
<property name="vlCausa" column="VL_CAUSA" not-null="false"/>
<property name="vlCustas" column="VL_CUSTAS" not-null="false"/>
<property name="numeroCheque" column="NR_CHEQUE" not-null="false"/>
<property name="dtCitacao" column="DT_CITACAO" not-null="false"/>
<property name="dtCadastro" column="DT_CADASTRO" not-null="true"/>
<property name="situacao" column="TP_SITUACAO" not-null="true"/>

<property name="acao" column="TP_ACAO" not-null="true"/>
<property name="instancia" column="TP_INSTANCIA" not-null="true"/>
<property name="rito" column="TP_RITO" not-null="true"/>
<property name="posicaoCliente" column="TP_POSICAO_CLIENTE" not-null="true"/>
<property name="jurisdicao" column="TP_JURISDICAO" not-null="true"/>
<property name="polo" column="TP_POLO" not-null="true"/>


<many-to-one name="pastaVinculada" class="PastaProcessoBO" column="ID_PASTA_PROCESSO_SUP" />
<many-to-one name="usuario" class="br.com.sapiensit.sigterra.configuracao.model.bo.UsuarioBO" column="ID_USUARIO" />
<many-to-one name="orgaoJudicial" class="OrgaoJudicialBO" column="ID_ORGAO_JUDICIAL" />

<!-- bi-directional many-to-many association to FuncionarioBO -->
<idbag name="advogadosTerracap" outer-join="true" table="TB_PASTA_ADVOGADO_INTERNO" lazy="true">
<collection-id column="ID" type="long">
<generator class="sequence">
<param name="sequence">SQ_PASTA_ADVOGADO_EXTERNO</param>
</generator>
</collection-id>
<key column="ID_PASTA_PROCESSO"/>
<many-to-many column="ID_FUNCIONARIO_ADVOGADO" class="br.com.sapiensit.sigterra.common.model.bo.FuncionarioBO"/>
</idbag>

<set name="partesContrarias" table="TB_PASTA_PARTE_CONTRARIA" cascade="all,delete-orphan">
<key column="ID_PASTA_PROCESSO" not-null="true"/>
<one-to-many class="ParteContrariaBO" />
</set>

<!-- bi-directional many-to-many association to ObjetoImobiliarioBO -->
<idbag name="objetos" outer-join="true" table="TB_PASTA_OBJETO_IMOBILIARIO" cascade="all,delete-orphan" lazy="true">
<collection-id column="ID" type="long">
<generator class="sequence">
<param name="sequence">SQ_PASTA_OBJETO_IMOBILIARIO</param>
</generator>
</collection-id>
<key column="ID_PASTA_PROCESSO"/>
<many-to-many column="ID_OBJETO_IMOBILIARIO" class="ObjetoBO"/>
</idbag>

<!-- bi-directional many-to-many association to DocumentoAdministrativoBO -->
<idbag name="documentosAdministrativos" outer-join="true" table="TB_PASTA_DOCUMENTO_ADM">
<collection-id column="ID" type="long">
<generator class="sequence">
<param name="sequence">SQ_PASTA_DOCUMENTO_ADM</param>
</generator>
</collection-id>
<key column="ID_PASTA_PROCESSO"/>
<many-to-many column="ID_DOCUMENTO_ADM" class="DocumentoAdministrativoBO"/>
</idbag>

<!-- bi-directional many-to-many association to AdvogadoExternoBO -->
<idbag name="advogadosExternos" outer-join="true" table="TB_PASTA_ADVOGADO_EXTERNO">
<collection-id column="ID" type="long">
<generator class="sequence">
<param name="sequence">SQ_PASTA_ADVOGADO_EXTERNO</param>
</generator>
</collection-id>
<key column="ID_PASTA_PROCESSO"/>
<many-to-many column="ID_ADVOGADO_EXTERNO" class="AdvogadoExternoBO"/>
</idbag>

<!-- bi-directional one-to-many association to AndamentoProcessoBO -->
<bag name="andamentosProcesso" table="TB_PASTA_ANDAMENTO" cascade="all,delete-orphan">
<key column="ID_PASTA_PROCESSO" not-null="true"/>
<one-to-many class="AndamentoProcessoBO" />
</bag>

<one-to-one name="encerramento" property-ref="pastaProcesso" cascade="all"/>

</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Criteria criteria = getSession().createCriteria(PastaProcessoBO.class).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
criteria.setFetchMode("pastaVinculada",FetchMode.JOIN);
criteria.setFetchMode("usuario",FetchMode.JOIN);
criteria.setFetchMode("orgaoJudicial", FetchMode.JOIN);
criteria.setFetchMode("advogadosTerracap", FetchMode.JOIN);
criteria.setFetchMode("partesContrarias", FetchMode.JOIN);
criteria.setFetchMode("objetos", FetchMode.JOIN);
criteria.setFetchMode("documentosAdministrativos", FetchMode.JOIN);
criteria.setFetchMode("advogadosExternos", FetchMode.JOIN);
criteria.setFetchMode("andamentosProcesso", FetchMode.JOIN);
criteria.setFetchMode("encerramento", FetchMode.JOIN);
Criterion crit = Restrictions.idEq(idPastaProcesso);
criteria.add(crit);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);


Top
 Profile  
 
 Post subject: lazy=false
PostPosted: Thu Feb 16, 2006 1:43 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
The simplest thing would be to declare them as lazy=”false” ant they will be initialized properly.

If you still want to use laziness than you have to force initialization by Hibernate.initialize( obj ) and then walk through collectionsanf call Hibernate.initailize( collection item ) because per javadoc:
* Note: This only ensures intialization of a proxy object or collection;
* it is not guaranteed that the elements INSIDE the collection will be initialized/materialized.
*
* @param proxy a persistable object, proxy, persistent collection or <tt>null</tt>
* @throws HibernateException if we can't initialize the proxy at this time, eg. the <tt>Session</tt> was closed

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: thanks!
PostPosted: Thu Feb 16, 2006 2:44 pm 
Newbie

Joined: Wed Feb 15, 2006 3:13 pm
Posts: 5
thanks, just one question!? what is the problem with fetch all properties!??!


Top
 Profile  
 
 Post subject: link
PostPosted: Thu Feb 16, 2006 2:57 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
this thread may answer your question :)
http://forum.hibernate.org/viewtopic.ph ... ight=fetch

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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.