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

    EJB Inheritance - Incorrect types

      I just used the new inheritance feature of EJB3 with the

      InheritanceType.SINGLE_TABLE
      strategy. There is a column for the type of the entity and each entity has a
      @DiscriminatorValue
      .

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



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

      If I call
      myEntity.getPartner():Collection<Partner>
      , I will get entites of type
      Partner
      . In the debugger, I can see that the attribute
      attributeOnlyInNaturalPerson
      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
      Carsten