-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: NonUniqueObjectException after reassociating root objects
PostPosted: Wed Jun 29, 2005 1:11 am 
Newbie

Joined: Wed Jun 29, 2005 12:31 am
Posts: 1
Hibernate 3.0.5
MySQL 4.1.12
Long lived Hibernate session (swing client app)

Every time the user does a save, we close the session and then reopen it, locking all the root objects into the new session (Session.lock() calls). All is fine while navigating the object graph (including lazy collections being fetched on the new session, etc). The trouble starts when we run an HQL that needs to fix up some paths stored in our persisted objects:
"from SomeClass where opPath like somePath" returns the objects we expect (both instances already in the cache as well as instances fetched from the DB). Modifying the path and then saving (from the root objects) generates the NonUniqueObjectException, and breaking at the throw point reveals that there seem to be two instances with the same key, one whose path we updated, and one other instance, same key and the old path.

The code is something like:

Iterator iter = session.createQuery("from Step step where step.opPath like somePath")
.list().iterator();
while(iter.hasNext()) {
Step step = (Step)iter.next();
step.setOperation(null, false);
step.setOpPath(newPath);
session.merge(step);
}

"Save" is simply doing a Session.saveOrUpdate for all roots objects, commiting the long lived transaction (same life span as the session) and then closing the session. Any help is much appreciated.

The exception is:

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:

at org.hibernate.engine.PersistenceContext.checkUniqueness(PersistenceContext.java:586)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:254)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:214)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:91)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)

at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)

at org.hibernate.engine.Cascades$5.cascade(Cascades.java:154)

at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:771)

at org.hibernate.engine.Cascades.cascade(Cascades.java:720)

at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:895)

at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:792)

at org.hibernate.engine.Cascades.cascade(Cascades.java:720)

at org.hibernate.engine.Cascades.cascade(Cascades.java:847)

at org.hibernate.engine.Cascades.cascade(Cascades.java:819)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.cascadeOnUpdate(DefaultSaveOrUpdateEventListener.java:316)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:299)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:214)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:91)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)

at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)

at org.hibernate.engine.Cascades$5.cascade(Cascades.java:154)

at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:771)

at org.hibernate.engine.Cascades.cascade(Cascades.java:720)

at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:895)

at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:792)

at org.hibernate.engine.Cascades.cascade(Cascades.java:720)

at org.hibernate.engine.Cascades.cascade(Cascades.java:847)

at org.hibernate.engine.Cascades.cascade(Cascades.java:819)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.cascadeOnUpdate(DefaultSaveOrUpdateEventListener.java:316)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:299)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:214)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:91)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)

at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)

at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:463)

.........


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.