• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

org.hibernate. NonUniqueObjectException

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic