Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Owning Side?

 
Nikhil Jain
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Nikhil Jain
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting very confused. Are there any good notes on explanation on it?
 
Tushar Roy
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seems to be a good presentation. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic