• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Composite key in collection of basic type

 
Darko Ristic
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all...
I have collection of values of basic type String, and want to have composite key in collection table.
Can anyone help with this in order how to make composite key in PERSON_EMAIL_ADDRESS table, consisting of PERSON_ID and EMAIL_ADDRESS?

This is entity with annotations:
 
James Sutherland
Ranch Hand
Posts: 553
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you are talking about DDL generation?

The CollectionTable annotation contains a uniqueConstraints attribute that you could use to define a unique constraint on these columns.
JPA does not provide a way to set the primary key constraint, other than the @Id annotation on an Entity. So, you could map Email as an entity instead of element collection.

You could also just define the table using your own DDL scripts.
 
Darko Ristic
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what if I say something like:


I'v checked table informations and it says EMAIL_ADDRESS is pk.
Beside, PERSON_EMAIL_ADDRESS is also pk.
Since I'm working with mySQL database, wonder if this is just case with mySQL or we could say it is the rule?
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

You can use composite keys with JPA. An example is shown here.

http://weblogs.java.net/blog/bleonard/archive/2006/11/using_composite.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic