Hello,
I got a very straightforward bi-directional mapping that's deployed to JBoss 6.0.0.Final (Hibernate 3.6.0.Final) as a JPA PU:
Code:
Convocation 1 <---> 0..* GraduandDetail 1 <---> 1 Student:
Here is the code:
Code:
@Entity
public class Convocation implements Serializable{
...
@OrderBy("acrossStageNumber")
@OneToMany(mappedBy = "convocation", cascade = {CascadeType.ALL})
private List<GraduandDetail> graduandDetails = new ArrayList<GraduandDetail>();
...
}
@Entity
public class GraduandDetail implements Serializable {
...
@ManyToOne
@JoinColumn(name = "convocation_fk", referencedColumnName="id")
private Convocation convocation;
private Integer acrossStageNumber;
...
@OneToOne(cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn
private Student student;
}
@Entity
public class Student implements Serializable {
...
private String name;
@OneToOne(mappedBy="student")
private GraduandDetail graduandDetail = new GraduandDetail(this);
...
}
After I add new students to a persistent convocation instance and then call EntityManager.merge(convocation), I expect Hibernate to merge the convocation instances along with the changes to the underlying graduands collection. However, I end up having a org.hibernate.TransientObjectException, with some prior tests, I also saw duplicate student entries in the database:
Quote:
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: ca.mcmaster.registrar.convocation.model.Student.graduandDetail -> ca.mcmaster.registrar.convocation.model.GraduandDetail
at org.hibernate.engine.CascadingAction$9.noCascade(CascadingAction.java:387) [:3.6.0.Final]
at org.hibernate.engine.Cascade.cascade(Cascade.java:172) [:3.6.0.Final]
Can you please be so kind to point the RTFM section of the Hibernate manual. I am out of clues now...
Thank you kindly.