• 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

Non Unique object Exception

 
Greenhorn
Posts: 7
Spring Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javax.persistence.PersistenceException: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:

I have mapped the files coorectly but i got this exception frequently..
 
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
Actually that error occurs when you try to "attach" an object that has the same id as an object that is already being managed.

For instance I can do this

MyObject someObjectICreateThatIsNotManaged = new MyObject();
someObjectICreateThatIsNotManaged.setId(1); //Yes setId should not be changable by code, but this is just for demonstration purposed

(Now within a Transaction/Session)
MyObject objectWithID1 = em.find(1,MyObject.class));
em.persist(someObjectICreateThatIsNotManaged); // This will get that exception thrown because objectWithID1 was loaded and is managed by the EntityManager, and when you then tried to "persist" someObjectICreateThatIsNotManaged, that object has the same id of 1 in it, and

someObjectICreateThatIsNotManaged != objectWithID1

Hope that helps clarify it.

Mark
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic