Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

How to use the many to many annotation?

 
Ranch Hand
Posts: 301
6
  • 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

 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • 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: 301
6
  • 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: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • 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?
 
You got style baby! More than this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!