About Question enthuware.oce-jpad.v6.2.442 :

Moderator: admin

Post Reply
swiss-chris
Posts: 11
Joined: Fri Jan 23, 2015 5:05 am
Contact:

About Question enthuware.oce-jpad.v6.2.442 :

Post by swiss-chris »

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."

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.442 :

Post by admin »

Let me quote Section 2.9 of JPA 2.0 Specification:
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.
...
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

alex
Posts: 42
Joined: Tue Feb 12, 2013 4:35 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.442 :

Post by alex »

@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?

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.442 :

Post by admin »

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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests