0 Replies Latest reply on Sep 7, 2006 3:16 AM by Carsten Rudat

    EJB Inheritance - Incorrect types

    Carsten Rudat Novice

      I just used the new inheritance feature of EJB3 with the

      strategy. There is a column for the type of the entity and each entity has a

      My entities are like:
      @DiscriminatorColumn(name = "INHERITANCETYPE", discriminatorType = DiscriminatorType.STRING)
      public class Partner ...
      public class NaturalPerson extends Partner ...
       protected String attributeOnlyInNaturalPerson;

      I have another entity with a relation to a
      entity (1-n-relation, so that a collection of
      is returned.

      If I call
      , I will get entites of type
      . In the debugger, I can see that the attribute
      is loaded from the database and instanciated to the object, BUT if I try to typecast the object to NaturalPerson, I get an ClassCastException.

      My current work around is to EntityManger.find(NaturalPerson.class, id) the entity again (this works) but I think this is a performance problem...

      Am I doing anything wrong with inheritance and relations, or is this really a bug?

      Best regards