• 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

many-to-many link table

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read from internet that ,  for many-to-many table relation, if the link table is a pure link table (i.e. only has the IDs from each of the two tables), then we don't need to create a POJO entity for it.  (see http://www.mkyong.com/hibernate/hibernate-many-to-many-relationship-example/) .  But if the link table includes some extra business fields then we need a separate POJO entity for it (see https://www.mkyong.com/hibernate/hibernate-many-to-many-example-join-table-extra-column-annotation/)

This makes good sense.  Now, if the link table consist of its own surrogate key  in addition to the two FK ids from two tables, do we need to create POJO for the link table ? i.e. if the link table looks like



should we consider stock_category_id  as extra business field  to create a POJO for this table ?
 
Saloon Keeper
Posts: 11186
244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The need to create any class at all is based purely on what you're going to use it for. You don't have to create a class if you're not interested in the identity of the relation. You don't have to create a class if you're not interested in any other business fields that may be associated with the relation.

So the question is: why do you need the relation to have a separate identifier, if a relation can uniquely be identified by a compound key?
 
Linwood Hayes
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:The need to create any class at all is based purely on what you're going to use it for. You don't have to create a class if you're not interested in the identity of the relation. You don't have to create a class if you're not interested in any other business fields that may be associated with the relation.

So the question is: why do you need the relation to have a separate identifier, if a relation can uniquely be identified by a compound key?



My understanding is :  If the link table consists of two fields (one is the PK from STOCK table and the other is the PK from CATEGORY table), then we don't need a separate class for this table.   But if the link table also has its own PK like some unique auto generated id, do we need a separate class to map to it ?  I guess we don't  but I am not sure and that's why I was asking.  Thanks.
 
It's a tiny ad. At least, that's what she said.
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!