[hibernate-issues] [Hibernate-JIRA] Created: (HHH-4446) NonUniqueObjectException and lost inserts

darko ostricki (JIRA) noreply at atlassian.com
Thu Sep 17 05:02:50 EDT 2009


NonUniqueObjectException and lost inserts
-----------------------------------------

                 Key: HHH-4446
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4446
             Project: Hibernate Core
          Issue Type: Bug
          Components: core
    Affects Versions: 3.3.1, 3.2.6
         Environment: occured in hibernate 3.3.1GA an 3.2.6GA on tomcat 5.5. with JNDI datasource configuration on HSQL DB 1.8.0.9 & SQL Server 2005
            Reporter: darko ostricki
         Attachments: hibernate.7z

used tables with native (identity) generator on both hsql and MSSQL 2005 Database.
Error occures randomly on Hibernate 3.3.1GA & 3.2.6GA therefore it's difficult to debug

I am experiencing a problem when persisting a large amount of Serialized objects within a single Transaction. (But not all objects of same type/mapping - primary Id's are null)
Sometimes the savOrUpdate doesn't actually perform an insert (skips an insert) - but assigns the bean in the persistence context the wrong generated Id.
The assigned generated id is actually genereted by an insert that should have been executed later in the batch.
The Insert that followed and got the correctly generated id, is inserted correctly to the database according to the transaction logs.
But the check of uniqueness fails because the bean in the persistencecontext which has NOT bean inserted properly (according to the transaction logs of the database and !!without!! errormessage) has the given id already assigned (in session context).

Maybe an example will make more clear what happens.
4 objects A,B,C,D will get persisted with saveOrUpdate the generated ids should be 0,1,2,3
Iteration 1 (OK) :
A -> saveOrUpdate -> Insert A into xyz (persist in Db) -> DB has Transact logs -> call identity delivers ID 0 -> bean in sessioncontext has id 0
Iteration 2 (something wents wrong) :
B -> saveOrUpdate -> Insert B into xyz (persist in Db) -> DB has NO Transact logs -> somehow bean gets id 2
Iteration 3 (OK) :
C -> saveOrUpdate -> Insert C into xyz (persist in Db) -> DB has Transact logs -> call identity delivers ID 1 because previous insert went wriong without error
-> bean in sessioncontext has id 1
Iteration 4 (Error happens) :
D -> saveOrUpdate -> Insert D into xyz (persist in Db) -> DB has Transact logs -> call identity delivers ID 2 -> bean in sessioncontext has id 2
-> checkOfuniqueness throws exception because a bean with the id is already in the session.

A,C,D are persisted accorifing to transaction logs of DB

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [de.tts.bd.model.HistoryEntry#4223]
at org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:613)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:326)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:534)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:526)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:522)
at de.tts.bd.business.exchange.serialize.ImportSerializable.persistEntity(ImportSerializable.java:260)


The error occures randomly on different mappings and was not reproducable with load tests of single Objecttypes @see the attachment zip file. But the attachment should show the environmental context how it happens.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list