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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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

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 Spring Roo Web Applications
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @onetomany
 
Similar Threads
OneToMany Mapping - Not a key
@OneToMany - Is thi bidirectional always?
Problem with @ManyToOne on a CompositeId
[OneToMany ManyToOne] null value in JoinColumn
what us mean mappedBy="item" ?