我在这里找到了我的任务的解决方案:mixing-joined-and-single-table-inheritance。问题包含混合两种继承策略的示例:与单个表连接。但是,是否可以将此注解映射转换为 XML 映射?
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "animals")
public abstract class Animal { ...
@MappedSuperclass
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type")
public abstract class Mammal extends Animal { ...
@Entity
@Table(name = "mammals")
@PrimaryKeyJoinColumn(name = "mammal_id")
@DiscriminatorValue(value = "dog")
public class Dog extends Mammal { ...
@Entity
@Table(name = "mammals")
@PrimaryKeyJoinColumn(name = "mammal_id")
@DiscriminatorValue(value = "cat")
public class Cat extends Mammal { ...