[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
Re: [eclipselink-users] JPA OneToOne with Primary Key FK Question
|
- From: "Tim Hollosy" <hollosyt@xxxxxxxxx>
- Date: Wed, 18 Jun 2008 16:29:03 -0400
- Delivered-to: eclipselink-users@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=Wj15wZRCCzLV/4zKiR6GVUfl7DGYPD0X6PBPlUgobyA=; b=m5D5KgknXccXhLcmZl3JSv1++J6C/MFV5LgRZ5bxoJVFDe0KzKA8d+xrCO0Ky41rhL nKShZT+J5bdn+Cqk0RN+w2YezL7oDcN0iexQG3ubFzdvGbbdPMlEgMALgvUYQMHgaH6A NVXzFBdaYc+SBONwQLyLz8O0I+ZfJWnRjJpts=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=sp7oJ+8I/14TFQEyK4Q26hrSDCC8s37tB6K1aKc+v5toTzrY/Ubtv3uTMTQaHxuCPn cJnlCKafR+uAotMrwZyKkONaQBj8gTDLUnw72FhwYn8G+D5lBVWmYaxWy6H16NBxoA4H qdstSNuzpDEe+V7zd1u0167yX41PX67OnOBSQ=
Thanks James, seems that particular model is not well suited to a
@OneToOne, we ended up implementing with a @SecondaryTable annotation
and that worked perfectly with minimal hassle.
Thanks,
Tim
On Wed, Jun 18, 2008 at 10:01 AM, James Sutherland <jamesssss@xxxxxxxxx> wrote:
>
> The issue is that you need to set the AccountDetails accountId2, it will not
> be set for you. You can do this by first persisting the Account, then
> creating the AccountDetails and setting its' account and accountId2 to the
> Account. You might also be able to do this in an event.
>
> see,
> http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Primary_Keys_through_OneToOne_Relationships
>
>
>
> Tim Hollosy wrote:
>>
>> I'm having a hard time with a OneToOne with a Primary Key as Foriegn
>> Key relationship.
>>
>> The secondary table is not getting the PK set, it's going in as null,
>> instead of grabbing
>>
>> Here's the EO's.
>>
>> Account and AccountDetails
>>
>> They both share account_id as PK's.
>>
>> I set the relationships on both sides and persist the account object,
>> the insert on the account_details fails with a null account_id.
>>
>> Account
>> ---
>> public class Accounts extends CreatedByModifiedByBaseEntity implements
>> Serializable {
>> @Id
>>
>> @GeneratedValue(generator="ACCOUNT_ID_SEQ",strategy=GenerationType.SEQUENCE)
>>
>> @SequenceGenerator(name="ACCOUNT_ID_SEQ",sequenceName="crm.\"ACCOUNT_ID_SEQ\"",allocationSize=1)
>> @Column(name="account_id")
>> private Long accountId;
>>
>> @OneToOne(mappedBy="accountId",cascade=PERSIST)
>> private AccountDetails accountDetails;
>>
>> Account_Details
>> ---
>> public class AccountDetails extends ModifiedByBaseEntity implements
>> Serializable {
>> @Id
>> @Column(name="account_id")
>> private Long accountId2;
>>
>> @OneToOne
>> @PrimaryKeyJoinColumn
>> private Accounts accountId;
>>
>> --
>> ./tch
>>
>
>
> -----
> ---
> 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/JPA-OneToOne-with-Primary-Key-FK-Question-tp17937146p17983350.html
> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
--
./tch