The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

CatchSandeepVaid (23) [Avatar] Offline
#1
[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;
}
reza_rahman (456) [Avatar] Offline
#2
Re: OneToOne Bidirectional Using @PrimaryKerJoinColumn
Sandeep,

This has already been reported and is in the errata. Please look at previous posts. The correction is:

PrimaryKeyJoinColumn(name="BILLING_USER_ID",referencedColumnName="BILLING_USER_ID")

Hope it helps,
Reza