Hi,
I am getting the NonUniqueObjectException. I am not able to see any reason why any other object would exist in memory. I have attached everything that I could think of as "relevant". I would be glad to provide any additional information you may need to solve this issue. I have spent almost a week trying to debug this error but it doesn't seem to go away! :(
Can any one out there throw some light on what I am doing wrong?
Thanks.
Best Regards,
Raghu
Hibernate version: 3.1
Mapping documents:
<hibernate-mapping> <class name="patient.businessobject.PatientRegistrationDetail" table="patient_registration_detail"> <id name="id" column="Id"> <generator class="increment"/> </id> <property name="registrationDateTime"/> <property name="firstName"/> <property name="lastName"/> <property name="middleName"/> <property name="telNumber1"/> <property name="telNumber2"/> <property name="emailAddress"/> <property name="sex"/> <property name="dateOfBirthDate" column="DateOfBirth"/> <property name="bloodGroup"/> <property name="remarks"/> <many-to-one name="registrationCentre" column="RegistrationCentreId" class="common.businessobject.Centre"/> <set name="addresses" table="patient_address" lazy="true" cascade="all"> <key column="PatientId"/> <composite-element class="patient.businessobject.PatientAddress"> <property name="type"/> <property name="street1"/> <property name="street2"/> <property name="street3"/> <property name="city"/> <property name="state"/> <property name="pincode"/> </composite-element> </set> </class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
//this is a function in DataAccessManager class public static void update(Object obj) { Session session = HibernateUtil.currentSession(); Transaction tx = session.beginTransaction(); session.update(obj); tx.commit(); }
I use servlet filter to close the session.
The above function is called in a struts action class as follows: DynaActionForm dynaForm = (DynaActionForm) form; PatientRegistrationDetail prd = extractFromForm(dynaForm); System.out.println("Updating PRD: "+prd); DataAccessManager.update(prd);
The code is bombing when update function is called. I can't understand how there can be another object with the same id. Because this is the *start* of a new servlet request.
The code of extractFromForm is as follows:
private PatientRegistrationDetail extractFromForm(DynaActionForm dynaForm) { PatientRegistrationDetail prd = (PatientRegistrationDetail) dynaForm.get("patientRegistrationDetail");
PatientAddress contactAddress = (PatientAddress)dynaForm.get("contactAddress"); PatientAddress permanentAddress = (PatientAddress)dynaForm.get("permanentAddress"); Set addresses = new HashSet(); addresses.add(contactAddress); addresses.add(permanentAddress); prd.setAddresses(addresses);
return prd; }
Full stack trace of any exception that occurs:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.lifeconnect.patient.businessobject.PatientRegistrationDetail#3] org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:628) org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:258) org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:216) org.hibernate.event.def.DefaultUpdateEventListener.performSaveOrUpdate(DefaultUpdateEventListener.java:33) org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70) org.hibernate.impl.SessionImpl.fireUpdate(SessionImpl.java:572) org.hibernate.impl.SessionImpl.update(SessionImpl.java:561) org.hibernate.impl.SessionImpl.update(SessionImpl.java:553)
Name and version of the database you are using: MySQL 4.1.10
The generated SQL (show_sql=true):
Hibernate: select this_.Id as Id5_0_, this_.name as name5_0_, this_.remarks as remarks5_0_ from centre_master this_ Hibernate: delete from patient_address where PatientId=? and type=? and street1=? and street2=? and street3=? and city=? and state=? and pincode=? Hibernate: insert into patient_address (PatientId, type, street1, street2, street3, city, state, pincode) values (?, ?, ?, ?, ?, ?, ?, ?) Hibernate: insert into patient_address (PatientId, type, street1, street2, street3, city, state, pincode) values (?, ?, ?, ?, ?, ?, ?, ?) Hibernate: select this_.Id as Id0_0_, this_.name as name0_0_, this_.password as password0_0_ from ums_user this_ Hibernate: delete from patient_address where PatientId=? and type=? and street1=? and street2=? and street3=? and city=? and state=? and pincode=? Hibernate: insert into patient_address (PatientId, type, street1, street2, street3, city, state, pincode) values (?, ?, ?, ?, ?, ?, ?, ?) Hibernate: insert into patient_address (PatientId, type, street1, street2, street3, city, state, pincode) values (?, ?, ?, ?, ?, ?, ?, ?)
Debug level Hibernate log excerpt:
|