File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Owning Side? 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 "Owning Side?" Watch "Owning Side?" New topic
Author

Owning Side?

Nikhil Jain
Ranch Hand

Joined: May 15, 2005
Posts: 385
Customer Table
ID
NAME,

PHONE Table
PHONE_ID
NUMBER
CUST_ID (Foregin Key)

In this case, would the phone be the owning side?

Secondly, is @JoinColumn used only in the owning side?


SCJP 1.4, SCWCD 1.4, SCBCD 1.5
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

The owning side of an entity relationship is the side where the primary key is stored in the database. Usually you can identify the reverse side of the owning side with the annotation attribute "mappedBy".

With @ManyToOne and @OneToMany relationships it's always the "Many" side.

Marco
Nikhil Jain
Ranch Hand

Joined: May 15, 2005
Posts: 385
But why always is the many side of one-to many /many to one bidirectinal relationship must be the owning side?
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

I think I read somewhere that this was a little weakness of the current versions of the JPA. And i read that there were some considerations if this could be changed in future versions. But unfortunately I don't know if this already has changed or will change some day.

Technically it's only natural to keep a simple foreign key on the many side in such relationships if you don't want to use unnecessary join tables. Anyway it has an impact on how you have to make cascaded updates to this relations. If you want your "One" side to be the owning side of your conceptual data model cascaded updates aren't automatically propagated to the "Many" side.

Perhaps someone with deeper understanding and insight in database design and the JPA may enlighten us
Tushar Roy
Greenhorn

Joined: Mar 26, 2008
Posts: 29
In unidirectional one to many relationship(using jointable) one-side has to be the owning side since many-side does not have the reference to one-side entity. Isnt it??


Tushar<br /> <br />SCJP 5 (95%)<br />SCWCD 1.4 (92%)<br />SCBCD 5 (93%)
Nikhil Jain
Ranch Hand

Joined: May 15, 2005
Posts: 385
I am getting very confused. Are there any good notes on explanation on it?
Tushar Roy
Greenhorn

Joined: Mar 26, 2008
Posts: 29
Go through the persistence specs. It will give you the best idea.
[ March 30, 2008: Message edited by: Tushar Roy ]
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Here is a nice presentation of the Java persistence API and EJB 3.0 in general. On page 12 is a short explanation of relationships and the owning side.

O'Reilly's "Enterprise JavaBeans 3.0" also covers JPA detailed enough.

What i personally find most confusing is the fact that your programming and data model of your application doesn't necessarily have to be the same as the data model actually persisted in the database. So it's often easier for me just to design and program what i really need and don't think too much about database concerns.

Marco
[ March 30, 2008: Message edited by: Marco Ehrentreich ]
Nikhil Jain
Ranch Hand

Joined: May 15, 2005
Posts: 385
seems to be a good presentation. Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Owning Side?