PDA

View Full Version : I dont understand why am I getting this exception


amishera
Jun 11th, 2008, 01:48 AM
Hi,
I have this problem. This is an exception from hibernate. But it is related to spring framework.

I have this very simple form. The corresponding controller is a simpleformcontroller. When the form is submitted once, a somewhat long transaction is initiated. But eventually the transaction completes successfully. But if the submit button is pressed again while the processing for first submission is continuing, I get the following exception:

org.springframework.orm.hibernate3.HibernateSystem Exception: a different object with the same identifier value was already associated with the session: [PC#71122]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [PC#71122]
Caused by:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [PC#71122]
at org.hibernate.engine.PersistenceContext.checkUniqu eness(PersistenceContext.java:586)
at org.hibernate.event.def.DefaultSaveOrUpdateEventLi stener.performUpdate(DefaultSaveOrUpdateEventListe ner.java:254)
at org.hibernate.event.def.DefaultSaveOrUpdateEventLi stener.entityIsDetached(DefaultSaveOrUpdateEventLi stener.java:214)
at org.hibernate.event.def.DefaultUpdateEventListener .performSaveOrUpdate(DefaultUpdateEventListener.ja va:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventLi stener.onSaveOrUpdate(DefaultSaveOrUpdateEventList ener.java:69)
at org.hibernate.impl.SessionImpl.update(SessionImpl. java:499)
at org.hibernate.impl.SessionImpl.update(SessionImpl. java:490)
at org.springframework.orm.hibernate3.HibernateTempla te$14.doInHibernate(HibernateTemplate.java:647)
at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:362)
at org.springframework.orm.hibernate3.HibernateTempla te.update(HibernateTemplate.java:644)
at org.springframework.orm.hibernate3.HibernateTempla te.update(HibernateTemplate.java:640)

There is an OpenSessionInView interceptor used. So I guess with each button press a new session begins. How come two objects with the same id belong to the same session? Because as the code stays the same, this would happen for a single submission only and we would not need a double click. But it is not happening for single submission. I wonder whether the spring beans being singletons has anything to do with it.

amishera
Jun 11th, 2008, 02:26 AM
Now I remember one thing. The form was session form.