3

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..

Community
  • 1
  • 1
Sampath Pasupunuri
  • 628
  • 1
  • 13
  • 25
  • I found a [solution](http://stackoverflow.com/questions/40679517/how-to-mix-inheritance-type-in-jpa) only using JPA openJPA without Hibernate. – Yan.F Nov 24 '16 at 08:50

1 Answers1

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

DataNucleus
  • 15,497
  • 3
  • 32
  • 37