Hi guys!
I have a problem with a cascading save that is performed in the wrong order.
Hibernate version:3.3.1.GA
Mapping documents:
Code:
@Entity
@Table(name = "psb")
public class Psb implements Serializable {
@EmbeddedId
private PsbId psbId;
@JoinColumns(value = {
@JoinColumn(name = "snr", insertable = false, updatable = false),
@JoinColumn(name = "psbnr", insertable = false, updatable = false) })
@ManyToOne(cascade = CascadeType.ALL)
private ExtraData extraData;
}
Code:
@Embeddable
public class PsbId Serializable {
@Column(name = "snr", nullable = false)
private Long snr;
@Column(name = "psbnr", nullable = false)
private Long psbnr;
}
Code:
@Entity
@Table(name = "extradata")
public class ExtraData implements Serializable {
@EmbeddedId
private PsbId psbId;
}
Code between sessionFactory.openSession() and session.close():
Psb psb = new Psb();
PsbId psbId = new PsbId();
psbId.setSnr(666);
psbId.setPsbnr(1);
ExtraData data = new ExtraData();
data.setPsbId(psbId);
psb.setExtraData(data);
entityManager.persist(psb);
--> this results in Hibernate trying an INSERT on the second extradata table
before inserting into the psb table, which violates foreign key constraints.
Why does the CascadeType.ALL annotation i put on the ManyToOne mapping
does not enable a cascading save in the correct order? Have i done any mistakes in my configuration?
Many thanks for any help and suggestions!
-lasse