Reputation: 7022
Is there a utility in Hibernate to quickly get a list of discriminator values that exist within an inheritance tree? It would be useful to avoid hard-coding this in certain SQL queries.
Upvotes: 1
Views: 971
Reputation: 153810
You can map the discriminator column to one property of your inheritance model base class:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "discriminator", discriminatorType = DiscriminatorType.STRING, length = 255)
public class BaseEntity {
@Column(name = "discriminator", insertable = false, updatable = false)
private String discriminator;
}
In HQL queries you can also use the class directive:
select e.class, e.id from YourEntity e
For SQL queries you can only use the predefined discriminator column. There's no utility to help you with that. Hibernate utilities are target towards entity queries (HQL or Criteria).
Upvotes: 2