File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate Spring problem with 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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Spring problem with Illegal attempt to associate a collection with two open sessions" Watch "Hibernate Spring problem with Illegal attempt to associate a collection with two open sessions" New topic
Author

Hibernate Spring problem with Illegal attempt to associate a collection with two open sessions

Carlos Gosu
Greenhorn

Joined: Feb 07, 2012
Posts: 2
Hello,

I'm having problems trying to update an object with a collection associated that was previously retrieved. If someone has faced the problem before it would be a great help.

The simplified code is the following:





Basicly the code that produces the exception is:


The implementation of saveMessage is:



I got the so called Illegal attempt to associate a collection with two open sessions in the getHibernateTemplate.saveOrUpdate(receiver); sentence. Any idea?

By the way I read around that it would be necessary to evict the object but I shouldn't evict the object out of the saveMessage for design reasons.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3858

Can you post the stack trace here?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Carlos Gosu
Greenhorn

Joined: Feb 07, 2012
Posts: 2
The stack trace is the following:

GRAVE: org.hibernate.HibernateException: Illegal attempt to associate
a collection with two open sessions
at
org.hibernate.collection.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:
410)
at
org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:
43)
at
org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:
101)
at
org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:
61)
at
org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:
55)
at
org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:
123)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:
293)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:
223)
at
org.hibernate.event.def.DefaultUpdateEventListener.performSaveOrUpdate(DefaultUpdateEventListener.java:
33)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:
70)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Spring problem with Illegal attempt to associate a collection with two open sessions