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

Are primary keys necessary for entities?

 
Steve Staarask
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to implicitly specify the pk for an entity?


For example, current Setup:





column_x is a primary key for Table X, and column_x and column_y make up the primary keys for Table Y.
These entities are extracted from the database by a value of column_x, which loads 1 X, with a list of multiple Ys.

I'm just wondering, is it possible to remove column_x from Class Y? Like can we be smart about this and somehow tell Hibernate, the column_x from X is part of the pk for Y? Or do we explicitly HAVE to have column_x in Y as well?
 
Dave Tolls
Ranch Hand
Posts: 2109
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate needs to know the Primary Key, as it uses it (in part) to determine equality and (I think) for its mappings in the background.
Remove the x column from Y and you remove Hibernate's ability to map Y objects properly.

Besides, as you can see in X the OneToMany specifies column_x as the mapping column. Remove that attribute and what do you map that relationship to?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic