[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] OneToOne, Composite Primary Key, Foreign Key
|
Hi everybody.I have problem with OneToOne-Mappings. The related entities share one field of the primary key. This field ist also a foreign key. So, it looks like:
Address-------
company PK, FKaddress PK
person FKstreet
cityPerson
------company PK
person PKfirstname
lastnameThe tables are currently mapped in following way:
public class Address implements Serializable{
public static final long serialVersionUID = 2L; @Id
@Column(name = "address") private int address;
@Id @Column(name = "company")
private int company; @Column(name = "street")
private String street; @Column(name = "city")
private String city; @OneToOne(cascade=CascadeType.ALL)
@JoinColumns({ @JoinColumn(name="person", referencedColumnName="person"),
@JoinColumn(name="company", referencedColumnName="company", insertable=false, nullable=false, updatable=false)
}) private Person person;
// getters and setters}
@Entity@Table(name = "person")
@IdClass(PersonPk.class)public class Person implements Serializable
{ private static final long serialVersionUID = 1L;
@Id @GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "person") private int person;
@Id @Column(name = "company")
private int company; @Column(name = "firstname")
private String firstname; @Column(name = "lastname")
private String lastname; @OneToOne(mappedBy="person", cascade=CascadeType.ALL)
private Address address; // getters and setters
}Reading data works without errors. But, e.g. if I want to update or insert an Address entity, all fields will be updated in database except the person column. What's wrong with my mapping?
Thanks for helping!
Max