File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Entity relationships Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Entity relationships" Watch "Entity relationships" New topic

Entity relationships

Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757

Source: Manning EJB 3 in Action

This two entities has one-to-one relationships between each others. As this program shows, a User entity object has-a one BillingInfo object.

I think the relationship occurs between the primary key field of each entities. Am I correct on this?

If yes, then how it is possible to have different types for those fields.
(I mean, the primary key field of "User" entity is a "String" value, but in BillingInfo, it is a "Long" value).
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
Your example describes a bidirectional one-to-one relationship. As such the table of the
owning side (the one without "mappedBy") has the foreign key (see JPA spec 2.1.7).
So in your example table User contains the primary key from table BillingInfo as
foreign key.

SCJP 5 (98%) - SCBCD 5 (98%)
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Thanks Ralph.
I agree. Here's the link:
subject: Entity relationships
It's not a secret anymore!