• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dealing with composite primary keys

 
noemi conde
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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 !!
 
E Erik Svensson
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks !!!

I'll try it now !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic