This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Entity relationships" Watch "Entity relationships" New topic
Author

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Entity relationships
 
Similar Threads
Issues with @PrimaryKeyJoinColumn
Naive question on "MappedBy" attribute of @OneToMany
OneToOne Bidirectional Using @PrimaryKerJoinColumn
Annotations doubt
Question about the type of JoinColumn.