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

How to use the many to many annotation?

 
Lisa Austin
Ranch Hand
Posts: 119
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

My homework includes using the many to many annotation however my text book does not discuss this and we haven't discussed this in the class.  My instructor likes to do these sort of things which is fine but I can't find a good example that I understand AND what supposedly how it can be used per what my instructor has suggested.

I say this because I found a few examples such as the one below but when I asked my instructor his response seems to imply that it doesn't need to be a join.    What he says and I quote
"If the field name is predictable it should know what to do" and "Use a list."

But I can't find any examples that doesn't use a join

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lisa Austin wrote:I say this because I found a few examples such as the one below but when I asked my instructor his response seems to imply that it doesn't need to be a join.    What he says and I quote
"If the field name is predictable it should know what to do" and "Use a list."

Having a ManyToMany relationship without having a join table sounds very weird from a database design point of view, because that would mean you have lots and lots of duplicate values in different tables. The join table takes care of this duplication (and you can even add specific columns to each record in the join table.
For example:
employee: id, first_name, last_name
project: id, name
employee_project: employee_id, project_id (and you could have additional columns like start_date and end_date as well)

Even the excellent Java Persistence WikiBook uses a JoinTable with a ManyToMany relationship as the only possible solution.

Hope it helps!
Kind regards,
Roel
 
Lisa Austin
Ranch Hand
Posts: 119
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:
Lisa Austin wrote:I say this because I found a few examples such as the one below but when I asked my instructor his response seems to imply that it doesn't need to be a join.    What he says and I quote
"If the field name is predictable it should know what to do" and "Use a list."

Having a ManyToMany relationship without having a join table sounds very weird from a database design point of view, because that would mean you have lots and lots of duplicate values in different tables. The join table takes care of this duplication (and you can even add specific columns to each record in the join table.
For example:
employee: id, first_name, last_name
project: id, name
employee_project: employee_id, project_id (and you could have additional columns like start_date and end_date as well)

Even the excellent Java Persistence WikiBook uses a JoinTable with a ManyToMany relationship as the only possible solution.

Hope it helps!
Kind regards,
Roel


Thank you Roel!  Sorry I'm so late, this got lost in my messages.  I appreciate the feedback.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lisa Austin wrote:I appreciate the feedback.

And what was finally the answer provided by your instructor on how to use the @ManyToMany annotation?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic