-->
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.  [ 5 posts ] 
Author Message
 Post subject: org.hibernate.NonUniqueObjectException
PostPosted: Thu Dec 29, 2005 5:53 am 
Newbie

Joined: Tue Oct 18, 2005 4:50 am
Posts: 3
Hi
I am using appfuse framework 1.8.2 and hibernate 3.0.5 I get the exception


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.impl.SessionImpl.saveOrUpdate(SessionImpl.java:463)
at org.springframework.orm.hibernate3.HibernateTemplate$18.doInHibernate(HibernateTemplate.java:671)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:356)
at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:668)
at com.nihilent.hrms.dao.hibernate.ResourceAllocationDAOHibernate.saveResourceAllocation(ResourceAllocationDAOHibernate.j
at com.nihilent.hrms.service.impl.ResourceAllocationManagerImpl.saveResourceAllocation(ResourceAllocationManagerImpl.java
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)


I get exception whenever I try to update the previously persisted objects.
First I get a List of POJOs from hibernate store them in session (HttpSession) where user performs the updates and then I get the list and then called getHibernateTemplate().saveOrUpdate(Object obj). for each object on List
POJO and childs that are in list have no equals and hashCode methods implemented.

Thanks


Top
 Profile  
 
 Post subject: 2 c
PostPosted: Thu Dec 29, 2005 1:49 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
The error means that Hibernate session holds an object of the same class and with the same ID as the object you are trying to saveOrUpdate( or its cascade reachable properties).

Such exception usually happens when session has loaded an object (perhaps indirectly as a property of another object) and now we supply a detached instance of the object to saveOrUpdate method.

As a general comment I would say that using Spring's HibernateTemplate is not good idea. It only seems convenient.
I recommend this approach
http://www.onjava.com/pub/a/onjava/2005 ... tions.html

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 29, 2005 2:02 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Good explanation of problem, bad advice.

Follow the FAQ: http://www.hibernate.org/116.html#A8


Top
 Profile  
 
 Post subject: advice
PostPosted: Thu Dec 29, 2005 2:21 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
I did not make myself clear enough. My advice definitely will not cure the problem. It is my general recommendation not to use HinernateTemplate

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: Thank you
PostPosted: Mon Jan 02, 2006 1:34 am 
Newbie

Joined: Tue Oct 18, 2005 4:50 am
Posts: 3
christian wrote:
Good explanation of problem, bad advice.

Follow the FAQ: http://www.hibernate.org/116.html#A8


Thank you. The problem solved. I checked for an object's id before saving and called merge() for objects already persisted.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.