问题描述
是否有可能迫使hibernate使用继承类型加入的鉴别器列?
根据JPA2.0规范,这应该是可能的,但我不能在hibernate中实现它。
示例:
我用Discriminator和 SecondaryTable $ SINGLE_TABLE c $ c>在子类上做这件事情。 I.E.
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name =TYPE)
@Entity
public class Parent
@Entity
@ DiscriminatorValue(C)
@SecondaryTable(name =child,pkJoinColumns = {@PrimaryKeyJoinColumn(name =id,referencedColumnName =id)})
public class Child extends Parent
当你添加一个新的子类时,你添加一个新的表格,其中包含相关的扩展数据字段。
Is it possible to force hibernate to use discriminator column for inheritance type joined?According to JPA2.0 specification this should be possible but i can't achieve it in hibernate.
Example:
@Inheritance(strategy = InheritanceType.JOINED) @ForceDiscriminator @DiscriminatorColumn(name="TYPE") @Entity public class Parent @Entity @DiscriminatorValue("C") public class Child extends ParentThis doesn't even create column TYPE in the table PARENT when using hibernate.hbm2ddl.auto create.
I know that InheritanceType.JOINED works without defining discriminator column but it's quite ineffective because then hibernate needs to create joins between parent and all children instead of just parent and one child when using information in discriminator column.
解决方案I've used SINGLE_TABLE with a Discriminator and a SecondaryTable on the subclass to do this very thing. I.E.
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="TYPE") @Entity public class Parent @Entity @DiscriminatorValue("C") @SecondaryTable(name = "child", pkJoinColumns = {@PrimaryKeyJoinColumn(name="id", referencedColumnName = "id")}) public class Child extends ParentWhen you add a new sub class you add a new table with the relevant extended data fields in it.
这篇关于Discriminator继承类型.JOINED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!