开发者

JPA: is it possible to change the PKs in an inheritance hierarchy?

I have the following DB design:

JPA: is it possible to change the PKs in an inheritance hierarchy?

(source: kawoolutions.com)

As you can see States, Countries, and Continents are all sub tables of GeoAreas. The interesting fact here is that States and Countries change their primary keys from the one (supposedly) inherited from GeoAreas.

Purpose: States and Countries are also used for postal addresses and I do not want to use the GeoAreas.id for that (refe开发者_StackOverflow社区rences to States and Countries not shown).

The question is: Is such a design supported by JPA? JPA 2.0 only? Not at all?

The problem I see is how the @Id annotation (used for all mappings) would be specified as the GeoArea class would look something like

public abstract class GeoArea implements Serializable
{
    @Id
    @Column(name = "id")
    protected Integer id;

    ...
}

and a subclass would further require another alternative @Id on some properties to be specified, like

public class Country extends GeoArea
{
    @Id
    @Column(name = "iso_code")
    private String isoCode;

    ...
}

Could anyone point me to the JPA spec where it denies such a scenario, if?


Section 2.4

The primary key must be defined on the entity class that is the root of the entity hierarchy or on a mapped superclass that is a (direct or indirect) superclass of all entity classes in the entity hierarchy. The primary key must be defined exactly once in an entity hierarchy.

i.e you cannot "redefine" the identity (by adding an extra field to the identity) in a subclass.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜