Hi There
I am currently struggling that the foreign Id (parent Id) is not inserted at the DB table of the child object. I think it has something to do with that the id of the parents id is automatically generated by the DB (autoincrement). So what do I wrong?
Let me explain the details of my setup. I am using Hibernate 3.3 with JPA and MySQL 5.1 I have a simple One-To-One bidirectional - Relationship.
@Entity @Table (name="main") public class Main { @Id @GeneratedValue (strategy=GenerationType.IDENTITY) @Column (name="id") private int id;
@OneToOne (mappedBy="main", cascade=CascadeType.ALL) private Child child; }
@Entity @Table (name="child") public class Child {
@Id @GeneratedValue (strategy=GenerationType.IDENTITY) @Column (name="id") private int id;
@OneToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER) @JoinColumn(name="main_id", unique=true, insertable=true, updatable=true) private Main main;
}
// at Java Runtime... Main m = new Main(); Child c = new Child(); m.setChild(c); // do only a save on the main, child automatically saved too entityManager.persist(m);
ISSUE: ==> If I now look at the table entries, there has been a child and a main persisted, the child and also the main got also their own primary id assigned, but the "main_id" of the child is empty ?
Did I miss something?
Thank you in advance regards Mark
|