考虑下面的课程
Product (抽象根类)
@Entity
@Table(name="PRODUCT")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="PRODUCT_TYPE")
public abstract class Product {
@Id
@GeneratedValue
@Column(name = "product_ent_id", insertable = false)
private int productEntId;
}
Car (扩展Product的另一个父类)
@Entity
@Table(name="CAR")
@DiscriminatorValue(value="Car")
@PrimaryKeyJoinColumn(name="car_ent_id")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="CAR_TYPE")
public abstract class Car extends Product {
@Column(name = "car_ent_id", insertable = false, updatable = false)
private int carEntId;
}
Speeder (扩展汽车的最后一个孩子)
@Entity
@Table(name="SPEEDER")
@DiscriminatorValue(value="Speeder")
@PrimaryKeyJoinColumn(name="speeder_ent_id")
public class Speeder extends Car {
@Column(name = "speeder_ent_id", insertable = false, updatable = false)
private int speederEntId;
}
当JPA使用鉴别器将我的对象模型映射到我的数据模型时,在单个父对子层次结构中使用鉴别器对我来说很好,鉴别器值被正确设置,但是当我添加了另一层次的层次结构 Speeder-extends-Car-extends-Product 时,鉴别器 Value 或不正常,
如果我只在单个继承中使用带有鉴别符的连接继承(例如,子对父),则鉴别器值正在其所尊重的列中正确映射,但现在我 added another hierarchy, the Speeder's discriminator value 是放在_2988051中的那个,并且 Car table 的 Car table 被保留为空值,我希望你能理解我在这里想要实现的目标,这可能吗?任何工作?周围有很多例子,但是我找不到一个能说明更深层次结构的例子,这个例子就像这样joined inheritance tables但是层次结构更深,周围的例子只有简单的层次结构,而其他人使用这种策略几乎相同 . 任何帮助或启发将不胜感激 .