Is it possible to use an enum as a discriminator value when using SINGLE_TABLE inheritance strategy?
See Question&Answers more detail:osIs it possible to use an enum as a discriminator value when using SINGLE_TABLE inheritance strategy?
See Question&Answers more detail:osIf what you are trying to achieve is to not to duplicate the discriminator values, there is a simple workaround.
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="FREQUENCY",
discriminatorType=DiscriminatorType.STRING
)
public abstract class Event {
}
@Entity
@DiscriminatorValue(value=Frequency.Values.WEEKLY)
public class WeeklyEvent extends Event {
…
}
public enum Frequency {
DAILY(Values.DAILY),
WEEKLY(Values.WEEKLY),
MONTHLY(Values.MONTHLY);
private String value;
…
public static class Values {
public static final String DAILY = "D";
public static final String WEEKLY = "W";
public static final String MONTHLY = "M";
}
}
Nothing to do with Hibernate/JPA really, but better than having to maintain the values in multiple places.