[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] OneToOne, Composite Primary Key, Foreign Key
|
Hi everybody.
I have another question in this case.
If I want to merge a new transient Person that has an detached Adress, the transient Person will be inserted into database, but the Adress object will not be updated in database. With OpenJPA it works.
Is this another bug in EclipseLink?
Thank you very much!
Best Regards,
Max
2009/8/17 Max Müller
<max.mueller.max@xxxxxxxxxxxxxx>
Hi Chris,
thanks for you help. Your second suggestion works, but I don't really like it. Do you nearly know when the bug will be fixed?
Best Regards,
Max
2009/8/14 christopher delahunt
<christopher.delahunt@xxxxxxxxxx>
Hello Max,
I believe you are hitting bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=280436
Can you try making Address' company attribute updateable=false, insertable=false, and the OneToOne updateable=true, insertable=true. Or you can add a new basic mapping for the person FK that is writable.
Best Regards,
Chris
Max Müller wrote:
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, FK
address PK
person FK
street
city
Person
------
company PK
person PK
firstname
lastname
The 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
------------------------------------------------------------------------
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users