“加入子类策略” - 什么是“对象标识符”?

时间:2015-06-30 13:10:24

标签: java hibernate jpa

Hibernate docs, § 5.1.6.2 - Joined subclass strategy中声明:

  

但是,每个子类必须声明一个包含对象标识符的表列。

它给出的例子如下:

@Entity @Table(name="CATS")
@Inheritance(strategy=InheritanceType.JOINED)
public class Cat implements Serializable { 
    @Id @GeneratedValue(generator="cat-uuid") 
    @GenericGenerator(name="cat-uuid", strategy="uuid")
    String getId() { return id; }

    ...
}

@Entity @Table(name="DOMESTIC_CATS")
@PrimaryKeyJoinColumn(name="CAT")
public class DomesticCat extends Cat { 
    public String getName() { return name; }
}

我猜测name不是对象标识符,因此DomesticCat类中的“表列”包含“对象标识符“?通常我需要做什么才能将这个特定的必需列添加到我的子类型中?

1 个答案:

答案 0 :(得分:0)

This is probably referring to the "id" field (not shown, but implied by the getId() method). This field is the unique identifier for the row in the "CATS" table containing the information you are looking for. It looks like it is setting the Type of id as String and is expecting a UUID. The sub-types will inherit this field due to their extension of the main class.