Hello,
I am developing a web app where I have two different object references to an object of the same type.
Ex:
The hibernate mapping of this object is of the form:Code:Class Building{ private Person admin; private Person contact; }
We are using Spring with Hibernate and dao support with the default hibernate filter OpenInSessionInViewFilter (Single Session mode). In the jsp form I have binded correctly both references. However when I submit the form with a different admin or contact hibernate is not able to update the current person with the new one, and I get a this type of exception: org.hibernate.HibernateException: identifier of an instance of com.cma.model.Person altered from 359 to 61HTML Code:<hibernate-mapping> <class name="com.cma.model.inmuebles.Building" table="buildings"> <id name="buildingId" type="integer"> <column name="buildingID" /> <generator class="identity" /> </id> some properties here .... <many-to-one name="admin" class="com.cma.model.Person" cascade="save-update" lazy="false"> <column name="adminID" /> </many-to-one> <many-to-one name="contact" class="com.cma.model.Person" cascade="save-update" lazy="false"> <column name="contactID" /> </many-to-one> </hibernate-mapping>
This is the stack trace of the exception:
Handler execution resulted in exception - forwarding to resolved error view
org.springframework.orm.hibernate3.HibernateSystem Exception: identifier of an in stance of com.cma.model.Persona altered from 358 to 273; nested exception is org.hibernate.HibernateException: identifier of an instance of com.cma.model.Person a altered from 358 to 273 org.hibernate.HibernateException: identifier of an instance of com.cma.model.Persona altered from 358 to 273
at org.hibernate.event.def.DefaultFlushEntityEventLis tener.checkId(DefaultFlushEntityEventListener.java :51)
at org.hibernate.event.def.DefaultFlushEntityEventLis tener.onFlushEntity
(DefaultFlushEntityEventListener.java:82)
at org.hibernate.event.def.AbstractFlushingEventListe ner.flushEntities(AbstractFlushingEventListener.ja va:190)
at org.hibernate.event.def.AbstractFlushingEventListe ner.flushEverythingToExecutions(AbstractFlushingEv entListener.java:70)
at org.hibernate.event.def.DefaultFlushEventListener. onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.j ava:730)
at org.hibernate.impl.SessionImpl.managedFlush(Sessio nImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(J DBCTransaction.java:86)
at org.springframework.orm.hibernate3.HibernateTransa ctionManager.doCommit(HibernateTransactionManager. java:490)
at org.springframework.transaction.support.AbstractPl atformTransactionManager.processCommit(AbstractPla tformTransactionManager.java:495)
at org.springframework.transaction.support.AbstractPl atformTransactionManager.commit(AbstractPlatformTr ansactionManager.java:468)
at org.springframework.transaction.interceptor.Transa ctionAspectSupport.doCommitTransactionAfterReturni ng(TransactionAspectSupport.java:258)
at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:106)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :144)
at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy6.saveCaptacion(Unknown Source)
at com.cma.webapp.action.CaptacionFormController.onSu bmit(CaptacionFormController.java:198)
at org.springframework.web.servlet.mvc.SimpleFormCont roller.processFormSubmission(SimpleFormController. java:258)
I tried implenting this situation in deferred close mode and it works for this case, however there are other parts of the application, where it fails to keep persistent objects associated with a specific session.
The transactions of the application are defined as follows:
I am fairly new to Spring and Hibernate, and I am not understanding why hibernate is not able to update these references.HTML Code:<bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager" ref="transactionManager"/> <property name="transactionAttributes"> <props> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="remove*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean>
Any suggestion on how to solve this will be appreciated!


Reply With Quote