Hi all, i have an entity that contains two other entities with @ManyToOne relationship.
@Entity
public class A extends Serializable{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@ManyToOne
@Cascade(CascadeType.SAVE_UPDATE)
private B b;
@ManyToOne
@Cascade(CascadeType.SAVE_UPDATE)
private C c;
}
If i try to save an A instance that have "B_ID" and "C_ID" of another A record i get the exception:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session
For example:
A table
| ID | B_ID | C_ID |
| 1 | 1 | null | // this works
| 2 | null | 1 | // this works
| 3 | 1 | x | // this throws the exception
| 4 | x | 1 | // this throws the exception
x=any value of existent B/C_ID
B_ID and C_ID are not unique in my model and (B_ID + C_ID) is not an unique constraint!!
What can i do?
Thank in advance.