Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unidirection Many-to-Many

 
Deepika Joshi
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EJB 3 in Action , page 283 , last 4 lines of page says,

if it's unidirection Many-to-Many relation, then only difference is that you do not need mapped by on inverse side,

doubt:
but do we need @Many-to-Many on inverse side?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but do we need @Many-to-Many on inverse side?

No. The opposite side probably doesn't even have the field.
 
Deepika Joshi
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks...
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EJB 3 in Action , page 283 , last 4 lines of page says,

if it's unidirection Many-to-Many relation, then only difference is that you do not need mapped by on inverse side

It's not quite correct what EJB 3 in Action says, since there is a difference in the defaults, too (see JPA spec 2.1.8.4 and 2.1.8.5.2).

Example: Assume there is a ManyToMany relationship between the entities Employee and Project. Assume further Employee is the owning side and the primary keys are empId and projId.

Unidirectional case: Assume the Employee class contains the field

@ManyToMany
private List<Project> myProjects;

Then the default primary key of the join table consists of the fields

EMPLOYEE_EMPID
MYPROJECTS_PROJID

Birectional case: Assume addionally, Project class contains the field

@ManyToMany(mappedBy="myProjects")
private List<Employee> myEmployees;

Then the default primary key of the join table consists of the fields

MYEMPLOYEES_EMPID
MYPROJECTS_PROJID

That's pretty easy to memorize, isn't it.
 
Deepika Joshi
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if it is unidirectional case,



then

Am I correct?
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there went something wrong with the editor. Can you please repeat the question ?
 
Deepika Joshi
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry it is not Editor's fault but it's my fault (I did not post my quest in correct way),

my doubt is cleared, please ignore my last post.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic