I am working on an application using Struts/Spring/Hibernate. I have struts calling services using spring's declarative transactions which then call the DAO which extends HibernateDAOSupport.
There is no lazy loading for any domain objects or collections. I have an object that has one to many relationships with it's children. The problem I am having is that when I save this object the first time it works fine but when I try to do an update, it fails with a NonUniqueObjectException.
I am calling getHibernateTemplate().saveOrUpdate(object). To further describe what excatly happens, when Object is saved the first time, we store it in the HttpSession. When user attempts to update this, I get it out of the HttpSession and map the modified attribute and call the saveOrUpdate. I donot have a unsave-value defined in my mapping. I can see in the logs that a new hibernate Session is opened before it tried to make the update. But it still gives the message " different object with the same identifier value was already associated with the session". I am copying the logs for reference:
-------------------------------------------------------------------
2005-11-24 17:05:27,072 ERROR com.roche.dss.affiliatedatacapture.web.action.LogE xceptionAction [ExecuteThread: '13' for queue: 'weblogic.kernel.Default'] Caught org.springframework.orm.hibernate3.HibernateSystem Exception: a different object with the same identifier value was already associated with the session: [com.roche.dss.extreportdomainmodel.Report#23534]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.roche.dss.extreportdomainmodel.Report#23534]
org.springframework.orm.hibernate3.HibernateSystem Exception: a different object with the same identifier value was already associated with the session: [com.roche.dss.extreportdomainmodel.Report#23534]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.roche.dss.extreportdomainmodel.Report#23534]
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.roche.dss.extreportdomainmodel.Report#23534]
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.DefaultSaveOrUpdateEventLi stener.performSaveOrUpdate(DefaultSaveOrUpdateEven tListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventLi stener.onSaveOrUpdate(DefaultSaveOrUpdateEventList ener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(Sessio nImpl.java:468)
at org.hibernate.impl.SessionImpl.saveOrUpdate(Sessio nImpl.java:463)
at org.springframework.orm.hibernate3.HibernateTempla te$18.doInHibernate(HibernateTemplate.java:673)
at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:358)
at org.springframework.orm.hibernate3.HibernateTempla te.saveOrUpdate(HibernateTemplate.java:670)
at com.roche.dss.extreportdomainmodel.dao.hibernate.R eportDAOHibernate.saveOrUpdateReport(ReportDAOHibe rnate.java:46)
at com.roche.dss.affiliatedatacapture.service.impl.Re portServiceImpl.save(ReportServiceImpl.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:292)
at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:155)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :122)
at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:96)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :144)
at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy14.save(Unknown Source)
at com.roche.dss.affiliatedatacapture.web.action.Save ReportAction.executeValidToken(SaveReportAction.ja va:66)
at com.roche.dss.affiliatedatacapture.web.action.Sync hroAction.execute(SynchroAction.java:40)
at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletI nvocationAction.run(ServletStubImpl.java:996)
at weblogic.servlet.internal.ServletStubImpl.invokeSe rvlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.TailFilter.doFilter(Tail Filter.java:28)
at weblogic.servlet.internal.FilterChainImpl.doFilter (FilterChainImpl.java:27)
at com.roche.dss.security.navigation.LoginFilter.doFi lter(LoginFilter.java:192)
at weblogic.servlet.internal.FilterChainImpl.doFilter (FilterChainImpl.java:27)
at weblogic.servlet.internal.WebAppServletContext$Ser vletInvocationAction.run(WebAppServletContext.java :6458)
at weblogic.security.acl.internal.AuthenticatedSubjec t.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Se curityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.inv okeServlet(WebAppServletContext.java:3661)
at weblogic.servlet.internal.ServletRequestImpl.execu te(ServletRequestImpl.java:2630)
at weblogic.kernel.ExecuteThread.execute(ExecuteThrea d.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.ja va:178)
-------------------------------------------------------------------------
org.springframework.transaction.interceptor.Transa ctionInterceptor [ExecuteThread: '14' for queue: 'weblogic.kernel.Default'] Getting transaction for com.roche.dss.affiliatedatacapture.service.ReportS ervice.save
2005-11-24 16:41:42,500 DEBUG org.springframework.orm.hibernate3.HibernateTransa ctionManager [ExecuteThread: '14' for queue: 'weblogic.kernel.Default'] Using transaction object [org.springframework.orm.hibernate3.HibernateTransa ctionManager$HibernateTransactionObject@1c8ce14]
2005-11-24 16:41:42,500 DEBUG org.springframework.orm.hibernate3.HibernateTransa ctionManager [ExecuteThread: '14' for queue: 'weblogic.kernel.Default'] Creating new transaction with name [com.roche.dss.affiliatedatacapture.service.ReportS ervice.save]
2005-11-24 16:41:42,500 DEBUG org.springframework.orm.hibernate3.HibernateTransa ctionManager [ExecuteThread: '14' for queue: 'weblogic.kernel.Default'] Opened new Session [org.hibernate.impl.SessionImpl@51b326] for Hibernate transaction
2005-11-24 16:41:42,516 DEBUG com.roche.dss.affiliatedatacapture.service.impl.Re portServiceImpl [ExecuteThread: '14' for queue: 'weblogic.kernel.Default'] begin save(report)
2005-11-24 16:41:42,563 DEBUG 2005-11-24 16:42:15,032 DEBUG org.springframework.orm.hibernate3.HibernateTempla te [ExecuteThread: '14' for queue: 'weblogic.kernel.Default'] Found thread-bound Session for HibernateTemplate
2005-11-24 16:42:15,063 DEBUG org.springframework.orm.hibernate3.HibernateTempla te [ExecuteThread: '14' for queue: 'weblogic.kernel.Default'] Not closing pre-bound Hibernate Session after HibernateTemplate
2005-11-24 16:42:18,453 DEBUG org.springframework.transaction.interceptor.RuleBa sedTransactionAttribute [ExecuteThread: '14' for queue: 'weblogic.kernel.Default'] Applying rules to determine whether transaction should rollback on org.springframework.orm.hibernate3.HibernateSystem Exception: a different object with the same identifier value was already associated with the session: [com.roche.dss.extreportdomainmodel.Report#23534]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.roche.dss.extreportdomainmodel.Report#23534]
2005-11-24 16:42:18,453 DEBUG org.springframework.transaction.interceptor.RuleBa sedTransactionAttribute [ExecuteThread: '14' for queue: 'weblogic.kernel.Default'] Winning rollback rule is: RollbackRule with pattern [Exception]
2005-11-24 16:42:18,469 DEBUG org.springframework.transaction.interceptor.Transa ctionInterceptor [ExecuteThread: '14' for queue: 'weblogic.kernel.Default'] Invoking rollback for transaction on com.roche.dss.affiliatedatacapture.service.ReportS ervice.save due to throwable [org.springframework.orm.hibernate3.HibernateSystem Exception: a different object with the same identifier value was already associated with the session: [com.roche.dss.extreportdomainmodel.Report#23534]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.roche.dss.extreportdomainmodel.Report#23534]]
-------------------------------------------------------------------------
Please help!!.
Thanks
Keerthi


Reply With Quote