I have an entity A with 2 OneToOne relations on a second entity B.
entity -- @OneToOne(cascade=CascadeType.PERSIST) --> entity
A -- @OneToOne(cascade=CascadeType.PERSIST) --> B
I want to manage the persistence from my entity A.
But when I call em.persist(o) hibernate throws the exception :
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [EntityB#null]
As my entities are not persisted yet, their id are nulls. The equals and hashcode of EntityB are not called.
You need to do something to assign an id value to the B. Normally, you’d use @GeneratedValue to do that.