Hibernate version:
Hibernate EntityManager 3.2.1.GA
Hibernate Annotations 3.2.1.GA
Hibernate 3.2.3
Mapping documents:
one end:
Code:
@OneToMany(mappedBy="contract", cascade=CascadeType.ALL)
public List<ContractNote> getContractNotes() {
return contractNotes;
}
public void setContractNotes(List<ContractNote> contractNotes) {
this.contractNotes = contractNotes;
}
and the other:
Code:
@ManyToOne
@JoinColumn(name = "CONTRACT_ID")
public Contract getContract() {
return contract;
}
public void setContract(Contract contract) {
this.contract = contract;
}
Code between sessionFactory.openSession() and session.close():What I'm basically doing is trying to add a
new ContractNote to an
existing Contract:
Code:
Contract c = em.find(Contract.class, id);
ContractNote cn = new ContractNote();
cn.setContract(c);
c.addContractNote(cn);
em.flush();
What happens is that I end up with two ContractNotes in the database and I can see in the hibernate log that indeed hibernate issues two inserts.
Shouldn't this work or am I doing something completely wrong?
/Magnus