mixing jpa inheritance strategies - inheritanceType.JOINED with inheritanceType.SINGLE_TABLE

Go To StackoverFlow.com

1

My class structure looks like this... I have two separate strategies being implemented here but the inheritance strategy of the root class i.e. InheritanceType.JOINED is being used throughout the hierarchy...

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "typeName", discriminatorType = DiscriminatorType.STRING, length =    100)
@Table(name="table_A")
public abstract class A{
...
}


@Entity
@Table(name = "table_B")
@PrimaryKeyJoinColumn(name = "ID_B")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("SVC")
public abstract class B extends A {
...
}

@Entity
@DiscriminatorValue("C")
public class C extends B {
... 
}

@Entity
@DiscriminatorValue("D")
public class D extends B {
...
}

When, I am creating an instance of 'D' and trying to persist it, hibernate is looking for a table named 'D' ...
I found a couple of people asking the same questions... but answers didn't help me...

mixing joined and single table inheritance and querying for all objects - same issue..
How to mix inheritance strategies with JPA annotations and Hibernate? - mixing single_table with joined.. this is not helpful in my case..

2012-04-03 23:58
by sampath
I found a solution only using JPA openJPA without Hibernate - Yan.F 2016-11-24 08:50


2

The JPA spec does not allow you to mix strategies in an inheritance tree; it requires you to set the inheritance strategy in the root Entity. JDO is the only spec allowing mixed strategies. You may find a JPA implementation that allows it, but it is non-portable

2012-04-04 06:52
by DataNucleus
Ads