Help coderanch get a
new server
by contributing to the fundraiser
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Illegal attempt to associate a collection with two open sessions

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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)
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
http://faq.javaranch.com/java/DontWakeTheZombies
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please start a new thread. Closing this thread.

Mark
 
Every time you till, you lose 30% of your organic matter. But this tiny ad is durable:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
    Bookmark Topic Watch Topic
  • New Topic