I'm trying to fetch to table so hibernate dont keeping hitting the DB but it seems that the fetch doesnt work
Hibernate version: 2.1.6
Mapping documents:
Code:
<class name="com.br.resource.csu.lembranca.dao.hibernate.persisted.Documento" table="SSC_documento">
<composite-id name="docPK" class="com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoPK">
<key-many-to-one name="codCli" column="COD_CLI"/>
<key-property name="inxDoc" column="INX_DOC"/>
</composite-id>
<set name="regras" inverse="true" lazy="true" cascade="all">
<key>
<column name="inx_doc"/>
<column name="cod_cli"/>
</key>
<one-to-many class="com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoRegra"/>
</set>
<property name="codInstalacao" column="COD_INSTALACAO"/>
<property name="codLivroLeitura" column="COD_LIVRO_LEITURA"/>
<property name="codLocalidade" column="COD_LOCALIDADE"/>
<property name="codLoteFaturamento" column="COD_LOTE_FATURAMENTO"/>
<property name="codMotivoExc" column="COD_MOTIVO_EXC"/>
<property name="codTipoDoc" column="COD_TIPO_DOC"/>
<property name="codUnidOper" column="COD_UNID_OPER"/>
<property name="datCriacaoFatura" column="DAT_CRIACAO_FATURA"/>
<property name="datEmissaoFatura" column="DAT_EMISSAO_FATURA"/>
<property name="datExc" column="DAT_EXC"/>
<property name="datFimCob" column="DAT_FIM_COB"/>
<property name="datInclusaoReg" column="DAT_INCLUSAO_REG"/>
<property name="datIniCob" column="DAT_INI_COB"/>
<property name="datPrevCorte" column="DAT_PREV_CORTE"/>
<property name="datProcArqOrg" column="DAT_PROC_ARQ_ORG"/>
<property name="datVenctoFatura" column="DAT_VENCTO_FATURA"/>
<property name="flgDebAut" column="FLG_DEB_AUT"/>
<property name="indContencioso" column="IND_CONTENCIOSO"/>
<property name="mesRefFatura" column="MES_REF_FATURA"/>
<property name="numFatura" column="NUM_FATURA"/>
<property name="qtdTentativa" column="QTD_TENTATIVA"/>
<property name="totFaturaAvisoDeb" column="TOT_FATURA_AVISO_DEB"/>
<property name="vlrFatura" column="VLR_FATURA"/>
</class>
<class name="com.br.resource.csu.lembranca.dao.hibernate.persisted.Cliente" table="SSC_CLIENTE">
<id name="codCli" column="COD_CLI" type="integer">
<generator class="increment"/>
</id>
<bag name="documentos" table="SSC_documento" inverse="true" lazy="true" cascade="all">
<key column="COD_CLI"/>
<one-to-many class="com.br.resource.csu.lembranca.dao.hibernate.persisted.Documento"/>
</bag>
<bag name="enderecos" table="SSC_endereco_cli" inverse="true" lazy="true" cascade="all">
<key column="COD_CLI"/>
<one-to-many class="com.br.resource.csu.lembranca.dao.hibernate.persisted.EnderecoCliente"/>
</bag>
<bag name="telefones" table="SSC_fone_cli" inverse="true" lazy="true" cascade="all">
<key column="COD_CLI"/>
<one-to-many class="com.br.resource.csu.lembranca.dao.hibernate.persisted.TelefoneCliente"/>
</bag>
<bag name="doctoPessoa" table="SSC_REL_CLI_DOCTO" inverse="true" lazy="true" cascade="all">
<key column="COD_CLI"/>
<one-to-many class="com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoCliente"/>
</bag>
<bag name="campanhas" table="SSC_REL_CLIENTE_CAMPANHA" inverse="true" lazy="true" cascade="all">
<key column="COD_CLI"/>
<one-to-many class="com.br.resource.csu.lembranca.dao.hibernate.persisted.ClienteCampanha"/>
</bag>
<property name="codClasse" column="COD_CLASSE"/>
<property name="codCliExt" column="COD_CLI_EXT"/>
<many-to-one name="codOrg" column="COD_ORG"/>
<property name="datInclusao" column="DAT_INCLUSAO"/>
<property name="dscEmail" column="DSC_EMAIL"/>
<property name="indSituaFornec" column="IND_SITUA_FORNEC"/>
<property name="nomCli" column="NOM_CLI"/>
<property name="vlrSldDev" column="VLR_SLD_DEV"/>
</class>
Code between sessionFactory.openSession() and session.close():Code:
public Collection findRetornoLight () throws DaoException {
Collection colDoc = null;
try {
colDoc = session.find("select doc from Documento doc inner join fetch doc.docPK.codCli cliente ");// +
// " where doc.datExc is null AND "+
// "doc.docPK.codCli in "+
// "(select cliCampanha.codCli from ClienteCampanha cliCampanha where cliCampanha.codCampanha = 1) AND "+
// "doc.docPK.codCli in "+
// "(select end.codCli from EnderecoCliente end where end.flgRetornoLight = 'S') OR "+
// "doc.docPK.codCli in "+
// "(select fone.codCli from TelefoneCliente fone where fone.flgRetornoLight = 'S') OR "+
// "doc.docPK.inxDoc in "+
// "(select docReg.doc.docPK.inxDoc from DocumentoRegra docReg where "+
// "docReg.flgRetornoLight = 'S' and docReg.indStatusRegra = 3 and "+
// "docReg.inxRegraCampanha.codCampanha = 1) and rownum < 100");
} catch (HibernateException e) {
e.printStackTrace();
throw new DaoException(e.getMessage());
}
return colDoc;
}
Name and version of the database you are using: oracle 8i
LOG :
Code:
21:32:57,119 INFO [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,127 INFO [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,135 INFO [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,143 INFO [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,152 INFO [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,160 INFO [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,168 INFO [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,180 INFO [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,194 INFO [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?