Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    16
    Rep Power
    0

    Default OneToOne Bidirectional Using @PrimaryKerJoinColumn

    [P-276 od EJB3 In Action book] states:
    "In a bidirectional relationship, the owning side of the relationship is the entity that stores the relationship in its underlying table."
    Now, consider the same example of User and BillingInfo.

    USER has USER_ID(PK)
    BILLING_INFO has BILLING_USER_ID (PK + FK)

    Now as BILLING_INFO table contains the FK, BillingInfo entity is the owning side of the relationship.
    Now according to the owning side definition, the classes should be:
    class BillingInfo{
    @Id
    @Column (name="BILLING_USER_ID")
    protected Long userId;

    @OneToOne
    @PrimaryKeyJoinColumn(name="USER_ID" referencedColumnName="USER_ID")
    User user;
    }



    class User{
    protected Long userId;

    @OneToOne(mappedBy="user")
    BillingInfo billingInfo;
    }

    but in the book, the classes are defined as :

    public class User {
    @Id
    @Column(name="USER_ID")
    protected Long userId;
    ...
    @OneToOne
    @PrimaryKeyJoinColumn(name="USER_ID",referencedCol umnName="BILLING_USER_ID")
    protected BillingInfo billingInfo;
    }


    public class BillingInfo {
    @Id
    @Column(name="BILLING_USER_ID")
    protected Long userId;
    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    You are confusing tables with entity classes.

  3. #3
    Join Date
    Oct 2009
    Posts
    16
    Rep Power
    0

    Default

    I am not mixing (confusion) tables and entities...
    The book clearly says:

    "In a bidirectional relationship, the owning side of the relationship is the entity that stores the relationship in its underlying table."

Similar Threads

  1. Bidirectional One-To-One using @PrimaryKeyJoinColumn
    By CatchSandeepVaid in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 11-08-2009, 02:38 PM
  2. Bidirectional Traversal with ListIterator
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 10:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •