user211157
user211157

Reputation:

JPA Entity Foreign Keys mapped to a Primary Key

Is it possible for a Primary Key of an nested Entity to be used as the Primary Key of the Nest Entity?

For Example:

If I had a Entity 'Staff' who has a primary key 'EID' and has the nested Entity 'Job'. The Entity 'Job' has a primary key 'JID', and a Discriminator type 'DTYPE' so that sub classes of Job may be stored in the DTYPE along with their various columns. I would like the primary key EID to be identical to JID for each different job added to my Staff table. Is this possible?

Or is this not allowed as 'Job' could be null, thus no JID could be mapped to be a primary key?

Is there a better way to model this?

Upvotes: 0

Views: 3659

Answers (2)

DataNucleus
DataNucleus

Reputation: 15577

You mean "Compound Identity" ? This is part of JPA2, so available if your implementation supports it, which DataNucleus does.

--Andy (DataNucleus)

Upvotes: 1

Related Questions