• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use the many to many annotation?

 
Ranch Hand
Posts: 333
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 333
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
reply
    Bookmark Topic Watch Topic
  • New Topic