Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@mappedBy

 
mallika shah
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,

A question says: A Flight bean and a Reservation bean have a @OneToMany relationship.
And asks which code represents the correct relationship.

How would a person know which is the owner side and which is the inverse side of the relationship to apply the @mappedBy attribute ?

mallika
 
Paul Michael
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm assuming this relationship is bidirectional because the mappedBy annotation was mentioned. This attribute pertains to the owning side of the relationship.

You can read the section on Entity Relationships from the book Enterprise JavaBeans 3.0 (5th Edition) for more details.


[ January 02, 2008: Message edited by: Michael Guevara ]
 
waleed zedan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Persistence specification:

The inverse side of a bidirectional relationship must refer to its owning side by use of the
mappedBy element of the OneToOne, OneToMany, or ManyToMany annotation. The
mappedBy element designates the property or field in the entity that is the owner of the relationship.

So , @mappedby should be placed on the inverse side not the owning side

Thanks,
 
Pawel Dolega
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Owner side of the relationship is the one which contains foreign key in db table
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic