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);
|