Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

org.hibernate. NonUniqueObjectException

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting these errors whenever I try to add or delete an object:
org.hibernate.NonUniqueObjectException: "a different object with the same identifier value was already associated with the session."

It is inconsistent though.

It is unidirectional and here is the mapping of involved object:


Any ideas why is this occuring?

Thanks!
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually this happens with detached objects. You might be taking an object that isn't associated to a Session, and when you are trying to do the add or delete, there is already an object loaded into the Session that has the same ID as the detached object. When using detached objects, try "merge"ing the detached object to the Session first.

Definition of the exception
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/NonUniqueObjectException.html

Another Javaranch post that might also help
https://coderanch.com/t/215214/ORM/java/updating-values-Hibernate

Mark
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark. I have read and tried those things in another thread but nothing works.

Somewhere, it is saying that it is a Hibernate bug.

On my project, I have a PK of the object to delete. What I did is, get all the related objects, iterate through it, compare their PK, if their equal, get that object and delete it. It's not the best way but at least it's working.

If you have further input, I appreciate it.

Thanks!
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the detached object, have you tried to call the merge() method to merge the object with the one that is already in the Session?

Mark
 
That's a very big dog. I think I want to go home now and hug this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic