Is that Possible to use discriminator with strategy = InheritanceType.TABLE_PER_CLASS?
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@DiscriminatorColumn(
name = "TYPE",
discriminatorType = DiscriminatorType.STRING
)
abstract class BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = “id”, updatable = false, nullable = false)
protected Long id;
}
@DiscriminatorValue("employee")
class Employee extends BaseEntity {
//contains different columns
}
@DiscriminatorValue("audit")
class Audit extends BaseEntity {
//contains different columns`
}
How to access data from BaseEntity based on discriminatorValue as "employee" or "audit"?`
To retrieve employees or audits you need to namedQueries :
and then you fetch them like this :