This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes PK in aggregated entity with other non-key attributes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "PK in aggregated entity with other non-key attributes?" Watch "PK in aggregated entity with other non-key attributes?" New topic
Author

PK in aggregated entity with other non-key attributes?

Shannon McGee
Greenhorn

Joined: Oct 01, 2009
Posts: 18
Is it possible to push the PK down into an aggregated entity that contains other non-key attributes?

@IdClass and @EmbeddedId allow you to define a PK (or composite key) in an aggregated entity.


But is it possible to map something like:



And yes, I know this is just a bad idea

Thanks!
Shannon
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
The JPA spec does not allow this, but some providers may support it.

If using EclipseLink you can use the @PrimaryKey annotation to define your primary key to any desired columns, no matter how they are mapped.

Probably best to mirror the id field in the entity.


TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
 
GeeCON Prague 2014
 
subject: PK in aggregated entity with other non-key attributes?