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.  [ 6 posts ] 
Author Message
 Post subject: Getting org.hibernate.NonUniqueObjectException.
PostPosted: Tue Mar 11, 2008 5:07 am 
Beginner
Beginner

Joined: Mon Oct 30, 2006 12:46 am
Posts: 26
Hi All,

I am getting org.hibernate.NonUniqueObjectException a different object with the same identifier value was already associated with the session: [com.cisco.hotice.data.beans.Command#1055765]. exeption

Here i am getting command bean instance and changing some fields and updating the new instance. But i am getting this exception.

Pls help me out how to adress fix for this.


Need to adress fix ASAP.

Thanks In Advance.

Parveen


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 11, 2008 8:25 am 
Newbie

Joined: Fri Apr 21, 2006 10:35 am
Posts: 13
Location: de
Can you show us the code that causes the NonUniqueObjectException? Are you sure you don't have two Command objects associated with a Hibernate session?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 11, 2008 8:43 am 
Beginner
Beginner

Joined: Mon Oct 30, 2006 12:46 am
Posts: 26
Am using like these to save/update data

try {
Session session = HibernateSessionFactory.getSession();

session.update(persistentInstance);
LogUtil.security("Update Command: "
+ persistentInstance.getCommandId());
} catch (RuntimeException re) {
log.error("update failed", re);
throw re;
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 11, 2008 8:53 am 
Beginner
Beginner

Joined: Mon Oct 30, 2006 12:46 am
Posts: 26
My log is shows :

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.cisco.hotice.data.beans.Command#1068956]
at org.hibernate.engine.PersistenceContext.checkUniqueness(PersistenceContext.java:549)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:251)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:214)
at org.hibernate.event.def.DefaultUpdateEventListener.performSaveOrUpdate(DefaultUpdateEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.update(SessionImpl.java:447)
at org.hibernate.impl.SessionImpl.update(SessionImpl.java:438)
at com.cisco.hotice.data.hibernate.CommandDAO.update(CommandDAO.java:153)

At some web page i have seen use sesion.saveorupdate() at the begining of the transaction if session is empty. But i am not sure how to implement that

Pls help me !!

Thanks In Advance.
Praveen


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 11, 2008 11:39 am 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
Check this http://www.laliluna.de/257.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 11, 2008 2:42 pm 
Beginner
Beginner

Joined: Tue Feb 26, 2008 2:04 pm
Posts: 28
Location: UK
sjhyam wrote:


this exception means that you already have an
object with the same identifier loaded in a cache
of a session you are trying to use again and
which hasn't been closed.

I'm not sure what HibernateSessionFactory.getSession()
does under the context you are using it. If it
re-associates your thread to a previously opened Session
then this a logical Exception to get.

A safe way to ensure you don't have duplicate objects
in your Session cache is to either evict the object
from cache or close the session and then use
HibernateSessionFactory.openSession().


mosa


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

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.