aspose file tools*
The moose likes Object Relational Mapping and the fly likes @onetomany Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "@onetomany" Watch "@onetomany" New topic
Author

@onetomany

rani vini
Greenhorn

Joined: May 13, 2009
Posts: 24
Can any one explain with small detail example
what is "mappedby" attribute in @OneToMany annotation and what is "referencedColumnName" attribute in @ManyToOne?

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Here's a little tutorial on the @OneToMany annotation:

Mapping One To Many Associations with Hibernate and JPA

The mappedBy attribute describes the name of the variable used in the @ManyToOne side of the relationship to map back to the @One side. So, in this example, there is a class named Player that has a variable in it named team:



Mapping One To Many Associations with Hibernate and JPA

-Cameron McKenzie
rani vini
Greenhorn

Joined: May 13, 2009
Posts: 24
Say on @onetomany side (Team side) I'll put " mappedby = team" and then on @manytoone side (Palyer side)I'll give that team instance name as "team1".
then hibernate will give exception. If I wont give "mappedby" option, what will happen?

Thanq very much.
rani vini
Greenhorn

Joined: May 13, 2009
Posts: 24
Say on @onetomany side (Team side) I'll put " mappedby = team" and then on @manytoone side (Palyer side)I'll give that team instance name as "team1".
then hibernate will give exception. If I wont give "mappedby" option, what will happen?

Thanq very much.
Lalit Bhatt
Ranch Hand

Joined: Dec 27, 2007
Posts: 69

With mappedBy the relationship is governed. The other side of the relationship owns it. On the many to one side, you give team as the name of the property.

See a tutorial here


Java-JavaEE Hibernate Spring Software Development Business Process Analysis
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: @onetomany