I just used the new inheritance feature of EJB3 with the
InheritanceType.SINGLE_TABLEstrategy. There is a column for the type of the entity and each entity has a
@DiscriminatorValue.
@Entity @DiscriminatorColumn(name = "INHERITANCETYPE", discriminatorType = DiscriminatorType.STRING) @DiscriminatorValue("Partner") public class Partner ... @Entity @DiscriminatorValue("NaturalPerson") public class NaturalPerson extends Partner ... protected String attributeOnlyInNaturalPerson;
Partnerentity (1-n-relation, so that a collection of
Partneris returned.
myEntity.getPartner():Collection<Partner>, I will get entites of type
Partner. In the debugger, I can see that the attribute
attributeOnlyInNaturalPersonis loaded from the database and instanciated to the object, BUT if I try to typecast the object to NaturalPerson, I get an ClassCastException.