You write:
(Remember that the Many side is always the owning in a OneToMany/ManyToOne relationship, so mappedBy is not required there.)
However, it seems this is only true for uni-directional OneToMany/ManyToOne relationships.
According to http://docs.oracle.com/javaee/6/api/jav ... oMany.html
"If the relationship is bidirectional, the mappedBy element must be used to specify the relationship field or property of the entity that is the owner of the relationship."
About Question enthuware.oce-jpad.v6.2.442 :
Moderator: admin
-
- Posts: 11
- Joined: Fri Jan 23, 2015 5:05 am
- Contact:
-
- Site Admin
- Posts: 10058
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.442 :
Let me quote Section 2.9 of JPA 2.0 Specification:
Paul.
HTH,The following rules apply to bidirectional relationships:
...
The many side of one-to-many / many-to-one bidirectional relationships must be the owning
side, hence the mappedBy element cannot be specified on the ManyToOne annotation.
...
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 42
- Joined: Tue Feb 12, 2013 4:35 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.442 :
@Entity
public class Category {
@JoinTable(joinColums=@JoinColumn(name="item")),
inverseJoinColumns=@JoinColumn(name="category")
Collection<Item> items
}
Shouldn't be there opposite names for joincolumns and inversejoincolumns?
Most of examples that I found use Entity identifer of the owning side as joinColumn.
Is there any difference?
public class Category {
@JoinTable(joinColums=@JoinColumn(name="item")),
inverseJoinColumns=@JoinColumn(name="category")
Collection<Item> items
}
Shouldn't be there opposite names for joincolumns and inversejoincolumns?
Most of examples that I found use Entity identifer of the owning side as joinColumn.
Is there any difference?
-
- Site Admin
- Posts: 10058
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.442 :
It wouldn't make any difference as long as you name it consistently and as long as you understand which column in the join table joins witch column in the entity table. It is a matter of perspective.
You should try it out.
HTH,
Paul.
You should try it out.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 44 guests