Consider my classes below
Product (Abstract Root class)
@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 (Another parent class that extends 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 (last child of the hierarcy that extends Car)
@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;
}
Using discriminator in a single parent-to-child hierarchy was doing fine to me when JPA maps my object model into my data model using discriminators, the discriminator values are properly set, but as I added another level of hierarchy which is Speeder-extends-Car-extends-Product, the discriminator values or not working properly,
If I'm only using joined inheritance using discriminator in a single inheritance(e.g. child-to-parent), the discriminator value is being mapped properly in their respected columns, but now I added another hierarchy, the Speeder's discriminator value is the one being placed in the Product table's discriminator column, and the discriminator column of the Car table is left as null value, I hope you can understand what I'm trying to achieve here, is this possible? any work arounds? there are so many examples around, but I cant find exactly one that illustrates a deeper hierarchy, an example like this joined inheritance tables but with a deeper hierarchy, the examples around has only simple hierarchy and almost the same with the others using this kind of strategy. Any help or enlightenment would be greatly appreciated.