What I'm doing here is: I log-in and call another Struts action to show the user some documents stored in the database....The first call actually works, but the others always thows this error. The strange thing is that that reading the logs it don't close the session neither the transaction, so why is it throwing this $*&#$ing error?
Can someone help?
Hibernate version: 3.1
Mapping documents:
Code:
<hibernate-mapping>
<class name="com.pix.hibernate.entities.Usuarios" table="usuarios" schema="dbo" catalog="vanpix">
<id name="idusuarios" type="integer">
<column name="idusuarios" />
<generator class="native" />
</id>
<many-to-one name="tabStatus" class="com.pix.hibernate.entities.TabStatus" fetch="select">
<column name="usr_status" not-null="true" />
</many-to-one>
<property name="usrLogin" type="string">
<column name="usr_login" length="10" not-null="true" unique="true" />
</property>
<property name="usrNome" type="string">
<column name="usr_nome" length="60" not-null="true" />
</property>
<property name="usrSenha" type="string">
<column name="usr_senha" length="32" not-null="true" />
</property>
<property name="usrEmail" type="string">
<column name="usr_email" length="70" not-null="true" />
</property>
<property name="usrCpf" type="string">
<column name="usr_cpf" length="11" not-null="true" />
</property>
<set name="cxpostalUsuarioses" inverse="true">
<key>
<column name="idusuarios" not-null="true" />
</key>
<one-to-many class="com.pix.hibernate.entities.CxpostalUsuarios" />
</set>
<set name="docAssinados" inverse="true">
<key>
<column name="idusuarios" not-null="true" />
</key>
<one-to-many class="com.pix.hibernate.entities.DocAssinado" />
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.pix.hibernate.entities.Documentos" table="documentos" schema="dbo" catalog="vanpix">
<id name="iddocumentos" type="long">
<column name="iddocumentos" />
<generator class="native" />
</id>
<many-to-one name="cxpostal" class="com.pix.hibernate.entities.Cxpostal" fetch="select">
<column name="idcxpostal" not-null="true" />
</many-to-one>
<property name="docIdentificacao" type="string">
<column name="doc_identificacao" length="20" not-null="true" />
</property>
<property name="docDtentrada" type="timestamp">
<column name="doc_dtentrada" length="23" not-null="true" />
</property>
<property name="docTamanho" type="long">
<column name="doc_tamanho" not-null="true" />
</property>
<property name="docDtenvio" type="timestamp">
<column name="doc_dtenvio" length="23" />
</property>
<set name="docAssinados" inverse="true">
<key>
<column name="iddocumentos" not-null="true" />
</key>
<one-to-many class="com.pix.hibernate.entities.DocAssinado" />
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Usin OpenSessionInViewFull stack trace of any exception that occurs:Code:
0:15:41,490 ERROR LazyInitializationException:19 - failed to lazily initialize a collection of role: com.pix.hibernate.entities.Cxpostal.documentoses, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.pix.hibernate.entities.Cxpostal.documentoses, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:97)
at org.hibernate.collection.PersistentSet.size(PersistentSet.java:114)
at com.pix.vo.ClientInfoVO.getDocumentosCxAtual(ClientInfoVO.java:69)
at com.pix.struts.action.ListaDocumentosAction.execute(ListaDocumentosAction.java:51)
Name and version of the database you are using:MSSql Server 2000
The generated SQL (show_sql=true):Debug level Hibernate log excerpt:10:15:19,286 DEBUG SessionImpl:219 - opened session at timestamp: 4975950722195456
10:15:19,302 DEBUG ThreadLocalSessionContext:290 - allowing method [beginTransaction] in non-transacted context
10:15:19,302 DEBUG ThreadLocalSessionContext:300 - allowing proxied method [beginTransaction] to proceed to real session
10:15:19,302 DEBUG JDBCTransaction:54 - begin
10:15:19,302 DEBUG ConnectionManager:415 - opening JDBC connection
10:15:19,428 DEBUG JDBCTransaction:59 - current autocommit status: false
10:15:19,428 DEBUG JDBCContext:194 - after transaction begin
10:15:36,061 DEBUG ThreadLocalSessionContext:300 - allowing proxied method [isOpen] to proceed to real session
10:15:36,801 DEBUG ThreadLocalSessionContext:300 - allowing proxied method [isOpen] to proceed to real session
10:15:41,490 ERROR LazyInitializationException:19 - failed to lazily initialize a collection of role: com.pix.hibernate.entities.Cxpostal.documentoses, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.pix.hibernate.entities.Cxpostal.documentoses, no session or session was closed
The code throwing the exception:Code:
public List getDocumentosCxAtual(){
Cxpostal cx = ((Cxpostal)cxsPostais.get(caixaPostalAtual));
Set documentos = cx.getDocumentoses();
ArrayList al = new ArrayList();
if(documentos.size() >0){
Iterator it = documentos.iterator();
while (it.hasNext()) {
DocumentoVO dVO = new DocumentoVO();
Documentos object = (Documentos) it.next();
dVO.setDocDtentrada(object.getDocDtentrada());
dVO.setDocDtenvio(object.getDocDtenvio());
dVO.setDocIdentificacao(object.getDocIdentificacao());
dVO.setDocTamanho(object.getDocTamanho());
dVO.setIddocumentos(object.getIddocumentos());
dVO.setNecessitaQtdAssinaturas(cx.getCxQtdAssinatura());
Set d = object.getDocAssinados();
if(d.contains(object)){
dVO.setIsAssinado(true);
}
al.add(dVO);
}
if(al!=null && al.size() >= 2){
Collections.sort(al);
}
}
return al;
}