-->
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.  [ 13 posts ] 
Author Message
 Post subject: Session is Closed Error during Marshalling of POJO
PostPosted: Mon Jan 23, 2006 7:23 pm 
Newbie

Joined: Tue Nov 25, 2003 12:26 pm
Posts: 12
I received the following error after upgrading from Hibernate 3.1 to Hibernate 3.1.1.

My application uses stateless session beans to retrieve POJO's from hibernate. Each method call involves opening a hibernate session, retrieving some data, closing the session and finally returning the POJO’s to the client.

I receive the error below during the marshall/unmarshall processing of returning a list of POJO’s on WebLogic 8.1.

The POJO's that are returned are retrieved using HQL. All many-to-one and bags are lazy loaded and are not retrieved in this query.

The object model is as follows.

A list of Labels.

Label contains a many-to-one relationship to NriApplication which contains a bag of FunctionKey.

I reverted back to Hibernate 3.1 and the methods began working correctly.

Arthur Fitt
arthur.fitt@netregulus.com


org.hibernate.SessionException: Session is closed!
at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:50)
at org.hibernate.impl.SessionImpl.getPersistenceContext(SessionImpl.java:1794)
at org.hibernate.proxy.BasicLazyInitializer.getReplacement(BasicLazyInitializer.java:100)
at org.hibernate.proxy.BasicLazyInitializer.invoke(BasicLazyInitializer.java:54)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:156)
at com.netregulus.common.businessmodel.shared.NriApplication$$EnhancerByCGLIB$$aad3fbcb.writeReplace(<generated>)
at sun.reflect.GeneratedMethodAccessor140.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at java.io.ObjectStreamClass.invokeWriteReplace(ObjectStreamClass.java:896)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1011)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
at java.util.ArrayList.writeObject(ArrayList.java:529)
at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:809)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1296)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
at weblogic.rmi.internal.CBVOutputStream.writeObject(CBVOutputStream.java:78)
at weblogic.rmi.internal.ServerRequest.unmarshalReturn(ServerRequest.java:94)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:293)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:247)
at com.netregulus.bt.core.util.ReferenceDataProviderEJB_895xpq_EOImpl_814_WLStub.getLables(Unknown Source)
at com.netregulus.bt.core.util.ReferenceDataProviderEJBProxy.getLables(ReferenceDataProviderEJBProxy.java:168)
at com.netregulus.ui.core.cache.ReferenceDataCache.getLabelWrapper(ReferenceDataCache.java:750)
at com.netregulus.ui.core.cache.ReferenceDataCache.getLabel(ReferenceDataCache.java:776)
at com.netregulus.ui.core.cache.ReferenceDataCache.getLabel(ReferenceDataCache.java:783)
at com.netregulus.ui.core.util.ErrorPage.getLabel(ErrorPage.java:232)
at jsp_servlet.__errorpage._jspService(__errorpage.java:168)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:463)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at com.netregulus.ui.core.filtersandlisteners.LoggingMDCFilter.doFilter(LoggingMDCFilter.java:60)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at com.netregulus.ui.core.filtersandlisteners.NriUploadFilter.doFilter(NriUploadFilter.java:91)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:326)
at weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:531)
at weblogic.servlet.internal.WebAppServletContext.handleException(WebAppServletContext.java:4056)
at weblogic.servlet.internal.WebAppServletContext.handleThrowableFromInvocation(WebAppServletContext.java:3834)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3780)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2644)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)

_________________
Arthur Fitt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 5:18 am 
Senior
Senior

Joined: Tue May 10, 2005 9:00 am
Posts: 125
The error confirms what you say in design:

- Collections are lazy initialized.
- You are closing session before marshalling the object to client.

Once the session is closed, you can not explore uninitialized lazy collections anymore (a lazy initialized collection will gather it's content, using the session, only when required).

The error sudden appearance is probably a consequence of the following hibernate improvement in 3.1.1 changelog:


http://opensource2.atlassian.com/projects/hibernate/browse/HHH-1290

Solution: don't manipulate object outside session to avoid problem.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 10:11 am 
Newbie

Joined: Tue Nov 25, 2003 12:26 pm
Posts: 12
tchize wrote:
Solution: don't manipulate object outside session to avoid problem.


I'm not accessing the collection in my code. It is the marshalling processes, which I have no control over, that is acessing the lazy collection.

Arthur

_________________
Arthur Fitt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 10:49 am 
Senior
Senior

Joined: Tue May 10, 2005 9:00 am
Posts: 125
Then close the session after the unmarshalling process, not before (using, for example, a session per request pattern).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 11:15 am 
Newbie

Joined: Tue Nov 25, 2003 12:26 pm
Posts: 12
tchize wrote:
Then close the session after the unmarshalling process, not before (using, for example, a session per request pattern).


I can't close the session after the marsalling process.The method is coded as below. A PersistenceManager is a wrapped hibernate session. This is a Stateless Session EJB method. It is the container marshalling the list of objects to return to the remote caller that is throwing the exception.

Code:
    public List getColumnLabels(String locale, String tableName) throws NetRegulusException {
        PersistenceManager persistenceManager = null;
        try {
            List labels = null;

            persistenceManager = PersistenceManagerFactory.createPersistenceManager();

            labels = persistenceManager.executeQuery("nriCached.columnLabels", new Object[] { locale, tableName })
                    .getResults();

            return labels;
        } finally {
            if (persistenceManager != null)
                persistenceManager.close();
        }
    }

_________________
Arthur Fitt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 11:16 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
When you never need the relations you may consider to write your own serialisation methods for your object or declare your collection as transient. I "hope" that this could work.

Alternatively, intialyze your objects.

Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 11:21 am 
Newbie

Joined: Tue Nov 25, 2003 12:26 pm
Posts: 12
LaLiLuna wrote:
When you never need the relations you may consider to write your own serialisation methods for your object or declare your collection as transient. I "hope" that this could work.

Alternatively, intialyze your objects.

Sebastian


It's not that I never need them. I don't need them for this particular use-case. I don't want to initialize them because that will run extra queries for data I am not using.

For other use-cases I need the collections populated and call a different EJB method that does initialize that collection.

I don't understand why 3.1.1 forces you to have all colections initialized before serialization when 3.1 and 2.1 did not.

In this case I have selected the exact set of data needed for my use-case.

_________________
Arthur Fitt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 12:22 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Try "factory.getCurrentSession()" and do not close session, transaction listener must close it.
http://www.hibernate.org/hib_docs/v3/re ... nt-session


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 12:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you can prove that we changed serialization behavior with a small test case then please submit to jira.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 2:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Yep, this is indeed a bug:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1392


Top
 Profile  
 
 Post subject: progress
PostPosted: Thu Mar 01, 2007 9:39 am 
Newbie

Joined: Mon Feb 05, 2007 6:46 am
Posts: 2
Location: Brussel
Has there been made any progress to this issue?

_________________
Sam


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 6:01 am 
Newbie

Joined: Thu Apr 08, 2004 4:28 am
Posts: 16
We have the same problem (Hibernate 3.1.3/Weblogic 9.2.1), see our log:

Code:
[masterdata] 2007-01-17 10:01:16,707 DEBUG [service.AffiliateManagementBean] findByCriteria()
[masterdata] 2007-01-17 10:01:18,159 DEBUG [resource.AffiliateDAO] # entities found: 1
[masterdata] 2007-01-17 10:01:18,781 ERROR [hibernate.LazyInitializationException] failed to lazily initialize a collection of role: com.vangenechten.system.masterdata.model.AddressZone.transportZones, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.vangenechten.system.masterdata.model.AddressZone.transportZones, 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.initialize(AbstractPersistentCollection.java:343)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentSet.equals(PersistentSet.java:350)
at weblogic.corba.utils.IndirectionValueHashtable.get(IndirectionValueHashtable.java:119)
at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1792)
at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1948)
at weblogic.iiop.IIOPOutputStream.writeObject(IIOPOutputStream.java:2209)
at weblogic.utils.io.ObjectStreamClass.writeFields(ObjectStreamClass.java:396)
at weblogic.corba.utils.ValueHandlerImpl.writeValueData(ValueHandlerImpl.java:235)
at weblogic.corba.utils.ValueHandlerImpl.writeValueData(ValueHandlerImpl.java:225)
at weblogic.corba.utils.ValueHandlerImpl.writeValue(ValueHandlerImpl.java:182)
at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1913)
at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1948)
at weblogic.iiop.IIOPOutputStream.writeObject(IIOPOutputStream.java:2209)
at weblogic.utils.io.ObjectStreamClass.writeFields(ObjectStreamClass.java:396)
at weblogic.corba.utils.ValueHandlerImpl.writeValueData(ValueHandlerImpl.java:235)
at weblogic.corba.utils.ValueHandlerImpl.writeValue(ValueHandlerImpl.java:182)
at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1913)
at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1948)
at weblogic.iiop.IIOPOutputStream.writeObject(IIOPOutputStream.java:2209)
at weblogic.utils.io.ObjectStreamClass.writeFields(ObjectStreamClass.java:396)
at weblogic.corba.utils.ValueHandlerImpl.writeValueData(ValueHandlerImpl.java:235)


We have opened a call at the BEA support, but we just receive the following answer : "It appears to be a Hibernite issue.".

Can anyone confirm this serialization problem is a Hibernate issue?
Is it normal that the Weblogic serialization call the equals method on a lazy object?
If I look in the java code of the PersistentSet.java I see this :

Code:
public boolean equals(Object other) {
      read();
      return set.equals(other);
   }


So the call of the equals method (in the Weblogic Serialization process) will also read the lazy data, but I don't need this data. should the equals method be changed?

Thanks in advance for any remarks!


Last edited by zombieman on Tue Mar 06, 2007 6:17 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 6:08 am 
Newbie

Joined: Thu Apr 08, 2004 4:28 am
Posts: 16
We have the same problem (Hibernate 3.1.3/Weblogic 9.2.1), see our log:

Code:
[masterdata] 2007-01-17 10:01:16,707 DEBUG [service.AffiliateManagementBean] findByCriteria()
[masterdata] 2007-01-17 10:01:18,159 DEBUG [resource.AffiliateDAO] # entities found: 1
[masterdata] 2007-01-17 10:01:18,781 ERROR [hibernate.LazyInitializationException] failed to lazily initialize a collection of role: com.vangenechten.system.masterdata.model.AddressZone.transportZones, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.vangenechten.system.masterdata.model.AddressZone.transportZones, 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.initialize(AbstractPersistentCollection.java:343)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentSet.equals(PersistentSet.java:350)
at weblogic.corba.utils.IndirectionValueHashtable.get(IndirectionValueHashtable.java:119)
at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1792)
at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1948)
at weblogic.iiop.IIOPOutputStream.writeObject(IIOPOutputStream.java:2209)
at weblogic.utils.io.ObjectStreamClass.writeFields(ObjectStreamClass.java:396)
at weblogic.corba.utils.ValueHandlerImpl.writeValueData(ValueHandlerImpl.java:235)
at weblogic.corba.utils.ValueHandlerImpl.writeValueData(ValueHandlerImpl.java:225)
at weblogic.corba.utils.ValueHandlerImpl.writeValue(ValueHandlerImpl.java:182)
at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1913)
at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1948)
at weblogic.iiop.IIOPOutputStream.writeObject(IIOPOutputStream.java:2209)
at weblogic.utils.io.ObjectStreamClass.writeFields(ObjectStreamClass.java:396)
at weblogic.corba.utils.ValueHandlerImpl.writeValueData(ValueHandlerImpl.java:235)
at weblogic.corba.utils.ValueHandlerImpl.writeValue(ValueHandlerImpl.java:182)
at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1913)
at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1948)
at weblogic.iiop.IIOPOutputStream.writeObject(IIOPOutputStream.java:2209)
at weblogic.utils.io.ObjectStreamClass.writeFields(ObjectStreamClass.java:396)
at weblogic.corba.utils.ValueHandlerImpl.writeValueData(ValueHandlerImpl.java:235)


We have opened a call at the BEA support, but we just receive the following answer : "It appears to be a Hibernite issue.".

Can anyone confirm this serialization problem is a Hibernate issue?
Is it normal that the Weblogic serialization call the equals method on a lazy object?
If I look in the java code of the PersistentSet.java I see this :

Code:
public boolean equals(Object other) {
      read();
      return set.equals(other);
   }


So the call of the equals method (in the Weblogic Serialization process) will also read the lazy data, but I don't need this data. should the equals method be changed?

Thanks in advance for any remarks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 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.