0

So I have a persistent object , that can be sent over a network. It can bounce back without changes and need to be saved as a separate entity.

When I try to save I get such exception. Exception in thread "AWT-EventQueue-0" org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:

  @Entity   
  class Foo
  {
   @Id @GeneratedValue
   int id;
   @Column
   String name
   @OneToMany
   List<Foo2> = new ArrayList<>();
  }
user3224416
  • 522
  • 5
  • 15

1 Answers1

0

Not sure if this answer can help your situation:

Basically, what hibernate is saying is that you have two objects which have the same identifier (same primary key) but they are not the same object.

I would suggest you break down your code, i.e. comment out bits until the error goes away and then put the code back until it comes back and you should find the error it.

It most often happens via cascading saves where there is a cascade save between object A and B, but object B has already been associated with the session but not on the same instance of B.

Hibernate Error: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

Community
  • 1
  • 1
Petro
  • 3,484
  • 3
  • 32
  • 59