PDA

View Full Version : Error duing update



kssnatha
Aug 24th, 2007, 05:11 AM
Hi friends,
We start a new project and we are using Struts + Spring + Hibernate.
We are using a generic dao implementation for all dao using advisors and interceptors. Also we delegate the actions to spring using a seperate xml called action-servlet.xml. I use transactions. I have one problem. I am able to add a record, edit a record. But when i update the record i got this error.

org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at org.hibernate.collection.AbstractPersistentCollect ion.setCurrentSession(AbstractPersistentCollection .java:410)
at org.hibernate.event.def.OnUpdateVisitor.processCol lection(OnUpdateVisitor.java:43)
at org.hibernate.event.def.AbstractVisitor.processVal ue(AbstractVisitor.java:101)
at org.hibernate.event.def.AbstractVisitor.processVal ue(AbstractVisitor.java:61)
at org.hibernate.event.def.AbstractVisitor.processEnt ityPropertyValues(AbstractVisitor.java:55)
at org.hibernate.event.def.AbstractVisitor.process(Ab stractVisitor.java:123)
at org.hibernate.event.def.DefaultSaveOrUpdateEventLi stener.performUpdate(DefaultSaveOrUpdateEventListe ner.java:293)
at org.hibernate.event.def.DefaultSaveOrUpdateEventLi stener.entityIsDetached(DefaultSaveOrUpdateEventLi stener.java:223)
at org.hibernate.event.def.DefaultUpdateEventListener .performSaveOrUpdate(DefaultUpdateEventListener.ja va:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventLi stener.onSaveOrUpdate(DefaultSaveOrUpdateEventList ener.java:70)
at org.hibernate.impl.SessionImpl.fireUpdate(SessionI mpl.java:564)
at org.hibernate.impl.SessionImpl.update(SessionImpl. java:552)
at org.hibernate.impl.SessionImpl.update(SessionImpl. java:544)
at com.revone.dao.hibernate.GenericDaoHibernateImpl.u pdate(GenericDaoHibernateImpl.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)

When this error is due to transaction or any other thing? Please help me.

Regards,
K. Siva Swamynatha.

Andrei Stefan
Aug 24th, 2007, 05:56 AM
Try searching the forum... there are many threads related to this exception.

kssnatha
Aug 24th, 2007, 06:09 AM
I searched a lot and couldn't find the solution since i am new to hibernate and springs. Is this error is due to transactions. I am using declarative transaction.

Thank you,

Regards,
K. Siva

xjBean
Aug 24th, 2007, 07:21 AM
It' maybe that a collection entity is being persistent state(that it's associating with a session) and you attempt to associate it with another new session.So this error happen:
'Illegal attempt to associate a collection with two open sessions'

Please check your code in your 'update method' of dao implementation