Hi,
I have a curious situation, let me explain it quickly:
I have 2 sessions, one for search and another for edit, so when I edit my object I load it into the second session, save it and then merge it back into the search session so that the changes are known. Basically, when I am deleting within my search session (before editing) I am able to delete my Object (ClassA), but when I perform some changes on it, save and merge, and then attempt to delete it within the search session after it has been merged I get a NonUniqueObjectException, specifying the "Different object with the same identifier value was already associated with the session" message.
Below is the code showing the OneToOne mapping that is causing me the problem (Note that it is ClassA that I am trying to delete, as he is the main Object):
Code:
@Entity
@Table(name = "CLASS_A", schema = "CONFIGURATION")
public class ClassA {
private Integer id;
...
private ClassB classB;
...
@OneToOne(mappedBy = "classA", cascade = {CascadeType.PERSIST, CascadeType.ALL}, optional = true, fetch = FetchType.EAGER)
@OnDelete(action = OnDeleteAction.CASCADE)
public ClassB getClassB(){
return classB;
}
public void setClassB(ClassB classB) {
this.classB = classB;
}
}
Code:
@Entity
@Table(name = "CLASS_B", schema = "CONFIGURATION")
public class ClassB {
private Integer id;
...
private ClassA classA;
...
@Id
@Column(name = "CLASS_A_ID", nullable = false, precision = 8, scale = 0)
@GeneratedValue(generator = "foreigner")
@GenericGenerator(name = "foreigner", strategy = "foreign", parameters = {
@Parameter(name = "property", value = "classA") })
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@OneToOne(cascade = { CascadeType.ALL }, optional = false)
@OnDelete(action = OnDeleteAction.CASCADE)
@Cascade({org.hibernate.annotations.CascadeType.DELETE_ORPHAN, org.hibernate.annotations.CascadeType.ALL})
@PrimaryKeyJoinColumn
public ClassA getClassA() {
return classA;
}
public void setClassA(ClassA classA) {
this.classA = classA;
}
}
I have tried to play with the annotations, but to no luck.
Any ideas anyone?
Thanks
Hibernate Core version is 3.3.2.GA