Issue
I have following situation:
Base class:
@Entity(name = "BaseEntity")
@Inheritance(strategy= InheritanceType.JOINED)
@DiscriminatorColumn(name="DISCR_COLUMN", discriminatorType = DiscriminatorType.STRING)
@Table(name = "base")
@DiscriminatorOptions(insert = true,force=true)
public abstract class Base implements Serializable {
Subclass:
@Entity(name = "SubclassEntity")
@DiscriminatorValue("A")
@Table(name="subclass")
@PrimaryKeyJoinColumn(name = "subclass_id", referencedColumnName = "base_id")
@DiscriminatorOptions(insert = true,force=true)
public class Subclass extends Base {
Repository:
public interface BaseRepository extends JpaRepository<Base, String>, JpaSpecificationExecutor<Base> {
The only problem I have is when I want to create a new Subclass
repository.saveAndFlush(Base base);
discriminator value is not saved and in DB appears NULL. I supposed it is set automatically by hibernate, isn't it ?
Solution
Attention: see comment below (!)
According to http://en.m.wikibooks.org/wiki/Java_Persistence/Inheritance section "Joined, Multiple Table Inheritance":
Hibernate does not support discriminator column for inheritance strategy: joined.
Answered By - Ralph