my dog learned polymorphism*
The moose likes Other Application Frameworks and the fly likes Illegal  attempt to associate a collection with two open sessions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Reply locked New topic
Author

Illegal attempt to associate a collection with two open sessions

pradeep arum
Ranch Hand

Joined: Oct 01, 2003
Posts: 130
This is the piece of code I am wrting
_______________________________________________

public List executeNamedQuery(String queryName,Long oid){


try
{
Query query = getHibernateTemplate().getNamedQuery(getSession(),queryName);
query.setParameter(0,oid);
return query.list();
}
catch (HibernateException e)
{
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}

}

And this is where i am calling from
______________________________________

List li=dms.executeNamedQuery("findContentObjects",identifier);
System.out.println("li.size()="+li.size());
Template temp=(Template)li.get(0);
Temp.setBizStatus("approve");
dms.create(temp);

Actually I am doing this behind create() method
____________________________________________________
public Serializable create(Object entityObj)
{
Serializable genId =getHibernateTemplate().save(entityObj);
return genId;
}


and this is the exception I am getting, can somebody please help.
_________________________________________________________________

org.springframework.orm.hibernate.HibernateSystemException: Illegal attempt to associate a collection with two open sessions; nested exception is net.sf.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
net.sf.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at net.sf.hibernate.collection.PersistentCollection.setCurrentSession(Lnet.sf.hibernate.engine.SessionImplementor Z(PersistentCollection.java:257)
at net.sf.hibernate.impl.WrapVisitor.processCollection(Ljava.lang.Object;Lnet.sf.hibernate.type.PersistentCollectionType Ljava.lang.Object;(WrapVisitor.java:42)
at net.sf.hibernate.impl.AbstractVisitor.processValue(Ljava.lang.Object;Lnet.sf.hibernate.type.Type Ljava.lang.Object;(AbstractVisitor.java:69)
at net.sf.hibernate.impl.WrapVisitor.processValues([Ljava.lang.Object;[Lnet.sf.hibernate.type.Type V(WrapVisitor.java:93)
at net.sf.hibernate.impl.SessionImpl.doSave(Ljava.lang.Object;Lnet.sf.hibernate.engine.Key;Lnet.sf.hibernate.persister.ClassPersister;ZZLnet.sf.hibernate.engine.Cascades$CascadingAction;Ljava.lang.Object Ljava.io.Serializable;(SessionImpl.java:931)
at net.sf.hibernate.impl.SessionImpl.doSave(Ljava.lang.Object;Ljava.io.Serializable;Lnet.sf.hibernate.persister.ClassPersister;ZLnet.sf.hibernate.engine.Cascades$CascadingAction;Ljava.lang.Object Ljava.io.Serializable;(SessionImpl.java:868)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(Ljava.lang.Object;Lnet.sf.hibernate.engine.Cascades$CascadingAction;Ljava.lang.Object Ljava.io.Serializable;(SessionImpl.java:790)
at net.sf.hibernate.impl.SessionImpl.save(Ljava.lang.Object Ljava.io.Serializable;(SessionImpl.java:749)
at org.springframework.orm.hibernate.HibernateTemplate$11.doInHibernate(Lnet.sf.hibernate.Session Ljava.lang.Object;(HibernateTemplate.java:301)
at org.springframework.orm.hibernate.HibernateTemplate.execute(Lorg.springframework.orm.hibernate.HibernateCallback Ljava.lang.Object;(HibernateTemplate.java:176)
at org.springframework.orm.hibernate.HibernateTemplate.save(Ljava.lang.Object Ljava.io.Serializable;(HibernateTemplate.java:298)
at vz.esm.edm.service.DocumentDMS.create(Ljava.lang.Object Ljava.io.Serializable;(Unknown Source)
at vz.esm.edm.web.DocUploadServlet.doPost(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse V(DocUploadServlet.java:148)
at javax.servlet.http.HttpServlet.service(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse V(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse V(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run()Ljava.lang.Object;(ServletStubImpl.java:1006)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse;Lweblogic.servlet.internal.FilterChainImpl V(ServletStubImpl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse V(ServletStubImpl.java:315)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run()Ljava.lang.Object;(WebAppServletContext.java:6718)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Lweblogic.security.subject.AbstractSubject;Ljava.security.PrivilegedAction Ljava.lang.Object;(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Lweblogic.security.acl.internal.AuthenticatedSubject;Lweblogic.security.acl.internal.AuthenticatedSubject;Ljava.security.PrivilegedAction Ljava.lang.Object;(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(Lweblogic.servlet.internal.ServletRequestImpl;Lweblogic.servlet.internal.ServletResponseImpl V(WebAppServletContext.java:3764)
at weblogic.servlet.internal.ServletRequestImpl.execute(Lweblogic.kernel.ExecuteThread V(ServletRequestImpl.java:2644)
at weblogic.kernel.ExecuteThread.execute(Lweblogic.kernel.ExecuteRequest V(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run()V(ExecuteThread.java:178)
at java.lang.Thread.startThreadFromVM(Ljava.lang.Thread V(Unknown Source)


SCJP1.4,SCBCD
Failure is not when you fall down; its only when you fail to get up again.
Lars Andr�n
Greenhorn

Joined: Dec 30, 2008
Posts: 3
I now have the same problem myself, and it seems to be due to a value being persisted over several sessions. You need to make sure that any save/update is done and then closing the session or committing the transaction before using it again.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

http://faq.javaranch.com/java/DontWakeTheZombies


GenRocket - Experts at Building Test Data
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Please start a new thread. Closing this thread.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
 
subject: Illegal attempt to associate a collection with two open sessions
 
Similar Threads
Axis in Weblogic Server8.1
IllegalArgumentException while submitting a form
Home & Remote interface
Problem with precompiled JSPs
Problem with precompiled JSPs