Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@onetomany

 
rani vini
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 69
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic