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:
posted 5 years ago
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.
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?