private String name;
//...
}
@Entity
public class Phone {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "phone_id")
private Long phoneId;
private String number;
@ManyToOne(cascade = CascadeType.ALL, optional=false)
@JoinColumn(name = "person_id")
private Person person;
}
And using them with:
Person p = new Person();
p.setName("A Person");
Phone ph1 = new Phone();
ph1.setNumber("212-1111");
ph1.setPerson(p);
Phone ph2 = new Phone();
ph2.setNumber("313-4444");
ph2.setPerson(p);
generates the following sql:
INSERT INTO PERSON (NAME) VALUES (?)
bind => [A Person]
INSERT INTO PHONE (NUMBER, PERSON_person_id) VALUES (?, ?)
bind => [212-1111, 1]
INSERT INTO PERSON (NAME) VALUES (?)
bind => [A Person]
INSERT INTO PHONE (NUMBER, PERSON_person_id) VALUES (?, ?)
bind => [313-4444, 2]
I tried to save/merge the Person right after creation, but that only gave me an extra insert into the person table:
INSERT INTO PERSON (NAME) VALUES (?)
bind => [A Person]
INSERT INTO PERSON (NAME) VALUES (?)
bind => [A Person]
INSERT INTO PHONE (NUMBER, PERSON_person_id) VALUES (?, ?)
bind => [212-1111, 2]
INSERT INTO PERSON (NAME) VALUES (?)
bind => [A Person]
INSERT INTO PHONE (NUMBER, PERSON_person_id) VALUES (?, ?)
bind => [313-4444, 3]
When I debug and inspect the objects, I can see that the phone object has the _persistence_* woven fields, but the person object does not. Is there a way to force eclipse to weave that class?
Am I missing something in my declarations? Does Eclipselink not support this style of relationships? I tried the same thing with hibernate, and it does the right thing.