Results 1 to 3 of 3
- 11-18-2009, 07:33 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 16
- Rep Power
- 0
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;
}
- 11-18-2009, 07:43 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
You are confusing tables with entity classes.
- 11-19-2009, 09:04 AM #3
Member
- Join Date
- Oct 2009
- Posts
- 16
- Rep Power
- 0
Similar Threads
-
Bidirectional One-To-One using @PrimaryKeyJoinColumn
By CatchSandeepVaid in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 11-08-2009, 02:38 PM -
Bidirectional Traversal with ListIterator
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 10:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks