• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Composite key in collection of basic type

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic