I asked this question a few months ago and never got an answer, hopefully someone can help me out this time. I think the problem I'm having is associated w/ a bug in Hibernate that's been around for a while:
http://opensource2.atlassian.com/projec ... se/HHH-511
I've got a setup where my DAO opens a session & transaction and a servlet filter commits and closes (per the instruction of Hibernate In Action - designing layered applications.)
In doGet() of my servlet I'm fetching an object, populating a form w/ the values (so they can be updated) and setting the object to an HttpSession.
In doPost() I get the object from the session, update the values from the form, and call saveOrUpdate() to persist it.
I call saveOrUpdate because they may be inserting a new record, not just updating an existing one.
This setup means that a session is opened/closed on doGet and another is opened/closed on doPost...so the problem I'm having is re-attaching an existing record on the session being utilized in doPost. Since the object I'm working with has two child objects (which are not mapped in the parent hbm.xml file) - apparently the save or saveOrUpdate methods are seeing the old object, not the new...as outlined in the error report link above.
Occasionally, I get this exception (same as bug report link above):
Code:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.app.Directory#1]
at org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:629)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:258)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:216)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:531)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:519)
...
Sometimes it works and the data is inserted/updated and sometimes it's not...and I get the exception...it's not consistent at all.
I've got several other forms where I use this same setup and it works flawlessly - but that is when working with single objects w/o children of their own.
Any ideas? I would have posted some code but it's long and wrapped up within many layers of my application...and probably wouldn't explain anything that I haven't already.
Hibernate version: 3.1.2
Name and version of the database you are using: MSSQL 2000