This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes OneToOne Bidirectional Using @PrimaryKerJoinColumn Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "OneToOne Bidirectional Using @PrimaryKerJoinColumn" Watch "OneToOne Bidirectional Using @PrimaryKerJoinColumn" New topic
Author

OneToOne Bidirectional Using @PrimaryKerJoinColumn

Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
[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",referencedColumnName="BILLING_USER_ID")
protected BillingInfo billingInfo;
}


public class BillingInfo {
@Id
@Column(name="BILLING_USER_ID")
protected Long userId;
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OneToOne Bidirectional Using @PrimaryKerJoinColumn
 
Similar Threads
Naive question on "MappedBy" attribute of @OneToMany
Issues with @PrimaryKeyJoinColumn
One-To-One Bidirectional - Owning Side & mappedBy property?
Annotations doubt
Question about the type of JoinColumn.