Hello every body. I have an objects witch has a lot of sets (customers, suppliers...), when the application loads, all the sets are loaded from the database. If I try for example to insert a new customer in the database, if there is no previous values in the DB every thing works fine and the record is created but if the table customer alreday contains records I got the exception: com.app.hibernate.PersistenceException: a different object with the same identifier value was already associated with the session: 257, of class: com.app.model.fields.OEM.
Each company has a collection of customers and each customer has a collection of oems.
Hibernate version:2.1.7
Mapping documents: -----company.hbm.xml----------------- <hibernate-mapping> <class name="com.app.model.Company" table="Company" dynamic-update="false" dynamic-insert="false" >
<id name="id" column="company_id" type="java.lang.Long" > <generator class="identity"> </generator> </id> <set name="customers" table="customer" lazy="false" inverse="false" cascade="all" sort="unsorted" >
<key column="company_id" />
<one-to-many class="com.app.model.Customer" /> </set> </class>
</hibernate-mapping>
-------------------------customer----------------- <hibernate-mapping> <class name="com.app.model.Customer" table="globalmkt_Customer" dynamic-update="false" dynamic-insert="false" >
<id name="id" column="customer_id" type="java.lang.Long" > <generator class="identity"> </generator> </id>
<property name="company" type="java.lang.Long" update="true" insert="true" > <column name="company_id" /> </property> <set name="oems" table="customer_to_field" lazy="false" inverse="false" cascade="all" sort="unsorted" >
<key column="customer_id" />
<many-to-many class="com.app.model.fields.PullDownField" column="pd_id" outer-join="auto" />
</set>
</class>
</hibernate-mapping>
--------------------------pulldown.hbm.xml-------------- <hibernate-mapping> <class name="com.app.model.fields.PullDownField" table="PullDownFields" dynamic-update="false" dynamic-insert="false" >
<id name="fieldId" column="field_id" type="java.lang.Long" > <generator class="identity"> </generator> </id>
<discriminator column="criterion" type="string" length="50" />
<property name="field" type="java.lang.String" update="true" insert="true" > <column name="field" unique-key="fieldcriterion" /> </property>
<property name="criterion" type="java.lang.String" update="false" insert="false" > <column name="criterion" unique-key="fieldcriterion" /> </property>
<subclass name="com.app.model.fields.OEM" dynamic-update="false" dynamic-insert="false" discriminator-value="oem" >
</subclass> </class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close(): persistor.updateCompany(value); persistor.commitTransaction(true);
updateCompany calls
protected void updateObject(Object object) throws PersistenceException { Session session = null; try { session = getSession(); beginTransaction(); if (!session.contains(object)) { session.update(object); } getSession().flush(); } catch (HibernateException e) { System.out.println("Exception e :"+e.getMessage()); rollback(); log.error("Cannot update object ["+object+"]", e); throw new PersistenceException(e); } finally { if (session != null) { finalizeCall(session, false); } } }
Full stack trace of any exception that occurs: com.app.company.components.Customer.addCustomer(Customer.java:150) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) org.apache.tapestry.listener.ListenerMap.invokeTargetMethod(ListenerMap.java:257) org.apache.tapestry.listener.ListenerMap.access$100(ListenerMap.java:46) org.apache.tapestry.listener.ListenerMap$SyntheticListener.invoke(ListenerMap.java:97) org.apache.tapestry.listener.ListenerMap$SyntheticListener.actionTriggered(ListenerMap.java:102) org.apache.tapestry.form.LinkSubmit.renderComponent(LinkSubmit.java:126) org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857) org.apache.tapestry.BaseComponent.renderComponent(BaseComponent.java:118) org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857) org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624) org.apache.tapestry.contrib.form.FormConditional.renderComponent(FormConditional.java:83) org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857) org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624) org.apache.tapestry.form.Form.renderComponent(Form.java:362) org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857) org.apache.tapestry.form.Form.rewind(Form.java:568) org.apache.tapestry.engine.RequestCycle.rewindForm(RequestCycle.java:432) org.apache.tapestry.form.Form.trigger(Form.java:582) org.apache.tapestry.engine.DirectService.service(DirectService.java:169) org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java:889) org.apache.tapestry.ApplicationServlet.doService(ApplicationServlet.java:198) org.apache.tapestry.ApplicationServlet.doPost(ApplicationServlet.java:327) javax.servlet.http.HttpServlet.service(HttpServlet.java:709) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214) org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198) org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152) org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118) org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102) org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) java.lang.Thread.run(Unknown Source) Caused by: com.app.hibernate.PersistenceException: a different object with the same identifier value was already associated with the session: 257, of class: com.app.model.fields.OEM com.app.db.BaseDB.updateObject(BaseDB.java:320) com.app.company.db.CompanyPersistorImpl.updateCompany(CompanyPersistorImpl.java:82) com.app.company.components.ProductInfo.addProductInformation(ProductInfo.java:145) ... 51 more Caused by: net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 257, of class: com.app.model.fields.OEM net.sf.hibernate.impl.SessionImpl.checkUniqueness(SessionImpl.java:1686) net.sf.hibernate.impl.SessionImpl.doUpdateMutable(SessionImpl.java:1452) net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1479) net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1402) net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114) net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436) net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:526) net.sf.hibernate.engine.Cascades.cascade(Cascades.java:452) net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503) net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:961) net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:866) net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:784) net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:747) net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1397) net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114) net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436) net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:526) net.sf.hibernate.engine.Cascades.cascade(Cascades.java:452) net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503) net.sf.hibernate.engine.Cascades.cascade(Cascades.java:482) net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1484) net.sf.hibernate.impl.SessionImpl.update(SessionImpl.java:1364) com.app.db.BaseDB.updateObject(BaseDB.java:313) ... 53 more
Name and version of the database you are using:Informix 9
|