When I run this code that process 8000 registers, after sometime it gives me a oracle error.
Why hibernate is allocating so much memory ? Also when I use show_sql = true, I see that it hits table CLIENTE a lot of times with the same query
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="codClasse" column="COD_CLASSE"/>
<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>
Code:
<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="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:
<class name="com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoRegra" table="SSC_rel_doc_regra">
<composite-id>
<key-many-to-one name="inxRegraCampanha" column="inx_regra_campanha"/>
<key-many-to-one name="doc" class="com.br.resource.csu.lembranca.dao.hibernate.persisted.Documento">
<column name="COD_CLI"/>
<column name="inx_doc"/>
</key-many-to-one>
</composite-id>
<property name="datAplicaRegra" column="dat_aplica_regra"/>
<property name="datPrevRegra" column="dat_prev_regra"/>
<property name="indStatusRegra" column="ind_status_regra"/>
<property name="vlrResultRegra" column="vlr_result_regra"/>
<property name="dscObs" column="dsc_obs"/>
<property name="flgRetornoLight" column="FLG_RETORNO_LIGHT"/>
</class>
Code between sessionFactory.openSession() and session.close():Code:
public String testConnection () {
HibernateDaoFactory hibernateDaoFactory = null;
String retorno;
try {
hibernateDaoFactory = new HibernateDaoFactory();
hibernateDaoFactory.openSession();
Iterator it = hibernateDaoFactory.session.find("from Documento as doc").iterator();
while ( it.hasNext() ) {
Documento doc2 = (Documento) it.next();
System.err.println(doc2.getNumFatura()+" - "+doc2.getDocPK().getCodCli().getNomCli());
Iterator itRegras = doc2.getRegras().iterator();
while (itRegras.hasNext()) {
DocumentoRegra docReg = (DocumentoRegra) itRegras.next();
System.err.println("docRegra = "+docReg.getDatAplicaRegra()+" FLAG "+docReg.getFlgRetornoLight());
}
}
System.err.println("finish");
hibernateDaoFactory.commitSession();
retorno = "<BR><B><font face='times new roman' size='3'>Conectado com sucesso</font></B>";
} catch (Throwable e) {
System.out.println(e);
retorno = "<BR><B><font face='times new roman' size='3'>Erro ao conectar ao JNDI."+e+"</font></B>";
} finally {
hibernateDaoFactory.closeSession();
}
return retorno;
}
Full stack trace of any exception that occurs:
[code]
15:38:25,095 WARN [JDBCExceptionReporter] SQL Error: 1000, SQLState: 72000
15:38:25,095 ERROR [JDBCExceptionReporter] ORA-01000: maximum open cursors exceeded
15:38:25,103 WARN [JDBCExceptionReporter] SQL Error: 1000, SQLState: 72000
15:38:25,104 ERROR [JDBCExceptionReporter] ORA-01000: maximum open cursors exceeded
15:38:25,104 ERROR [JDBCExceptionReporter] could not load: [com.br.resource.csu.lembranca.
dao.hibernate.persisted.Documento#com.br.resource.csu.lembranca.dao.hibernate.persisted.Do
cumentoPK@59563878]
java.sql.SQLException: ORA-01000: maximum open cursors exceeded
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oopen.receive(Oopen.java:118)
at oracle.jdbc.ttc7.TTC7Protocol.open(TTC7Protocol.java:472)
at oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:492)
at oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:511)
at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:
209)
at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:
192)
at oracle.jdbc.driver.OracleConnection.privatePrepareStatement(OracleConnection.ja
va:778)
at oracle.jdbc.driver.OracleConnection.prepareStatement(OracleConnection.java:634)
at java.lang.reflect.Method.invoke(Native Method)
at com.mchange.v2.c3p0.stmt.GooGooStatementCache$2.run(GooGooStatementCache.java:3
25)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsyn
chronousRunner.java:148)
15:38:25,106 ERROR [PersistentCollection] Failed to lazily initialize a collection
net.sf.hibernate.JDBCException: could not load: [com.br.resource.csu.lembranca.dao.hiberna
te.persisted.Documento#com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoPK@5
9563878]
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:422)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2117)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1991)
at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1953)
at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:69)
at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:204)
at net.sf.hibernate.type.ComponentType.resolveIdentifier(ComponentType.java:405)
at net.sf.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:145)
at net.sf.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:427)
at net.sf.hibernate.loader.Loader.getRowFromResultSet(Loader.java:200)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:281)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.ja
va:133)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:990)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:965)
at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:93)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractColl
ectionPersister.java:284)
at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3268)
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollectio
n.java:195)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java
:71)
at net.sf.hibernate.collection.Set.hashCode(Set.java:383)
at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:392
)[code]
Name and version of the database you are using: oracle 8i[/code]