• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Dealing with composite primary keys

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all !

I've got a problem, one of my entities (A) has a composite primary key, this PK is composed by an Integer which identifies another entity (B) and two strings more, so the three of them identifies this entity (A), here is the problem, can I implement this using Hibernate ??? or I should have a surrogate key instead of this primary key, in that case I suppose I should have an Unique index, indexing all three fields in order to maintain the restrictions of a primary key in those fields.
My Daos should implement a GenericDao parameterized by the type of the Entity, and the type of the primary key, and my primary key don't have a type !!!

Can you help me ???

I found some examples using composite keys, but in all of them, the keys identifies different entities, so you can write another object with an @Embeddable annotation with all the keys, but I get lost because of these two strings, that they don't identify anything at all.

I think I should use the surrogate key option, am I correct ???

What do you think ? Any idea ?? I don't find something like this in google :S

Any idea is welcome,

Thanks in advance !!
 
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(NB: I've used composite keys in jpa, hopefully I can help a bit at least)


has a composite primary key, this PK is composed by an Integer which identifies another entity (B) and two strings more, so the three of them identifies this entity (A),



In jpa I would do something like



Then you need to call


HTH

cheers
Erik
 
noemi conde
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks !!!

I'll try it now !
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic