根据Hibernate参考文档,在使用Hibernate的XML元数据时,应该可以混合使用不同的继承映射策略:http:
//docs.jboss.org/hibernate/stable/core/reference/en/html/inheritance.html#inheritance -混合- tableperclass-tablepersubclass
但是," Hibernate注释参考指南"的相应部分不包括:
http://docs.jboss.org/hibernate/stable/annotations/reference/en/html/entity.html#d0e1168
另一方面,JavaDocs建议混合继承策略应该是可能的.例如,在javax.persistence.DiscriminatorColumn中,它说:
策略和鉴别器列仅在实体类层次结构或子层次结构的根中指定,其中应用了不同的继承策略.
以下是我试图实现的映射的示例.我想在层次结构的根附近使用table-per-subclass映射,但是更改为叶子附近的table-per-class-hierarchy映射.这是一些示例代码:
@Entity
@Inheritance( strategy = InheritanceType.JOINED )
public abstract class A implements Serializable
{
@Id
private String id;
// other mapped properties...
}
@Entity
@Inheritance( strategy = InheritanceType.SINGLE_TABLE )
public class BB extends A
{
// other mapped properties and associations...
}
@Entity
public class BB1 extends BB
{
// other stuff, not necessarily mapped...
}
@Entity
public …
Run Code Online (Sandbox Code Playgroud)