Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] OneToOne, Composite Primary Key, Foreign Key

Merge will only merge changes to objects, if the Address did not change, it
will not be committed.  Also if the relationship is not marked cascade
merge, then the merge of the Person will not cascade to the Address.

Perhaps include the details of what you are doing and what you expect to
occur.


Max Müller-2 wrote:
> 
> 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
>>>>
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/OneToOne%2C-Composite-Primary-Key%2C-Foreign-Key-tp24970561p25151360.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top