[jboss-user] [EJB 3.0] - EJB Inheritance - Incorrect types

CarstenRudat do-not-reply at jboss.com
Thu Sep 7 03:16:41 EDT 2006


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

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3969997#3969997

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3969997



More information about the jboss-user mailing list