Discriminator in InheritanceType.JOINED

后端 未结 2 1146
北恋
北恋 2020-12-24 09:08

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

相关标签:
2条回答
  • 2020-12-24 09:27

    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 Parent
    

    When you add a new sub class you add a new table with the relevant extended data fields in it.

    0 讨论(0)
  • 2020-12-24 09:36

    Do you want to use @Inheritance(strategy=InheritanceType.SINGLE_TABLE)?

    0 讨论(0)
提交回复
热议问题