0 Replies Latest reply on Dec 27, 2007 3:54 PM by lpmon

    @DiscriminatorValue: find not returning subclasses

    lpmon Novice

      Env: JBoss AS 4.0.5.GA w/EJB3

      I have looked over several different docs that describe how to use entity inheritance w/ SINGLE_TABLE. I used those examples as the basis for my code. I have a base class Units and have subclasses RFUnit and EMUnit.

      (em is an entitymanager object)

      When I do em.find() or em.getResultList() it always returns the base class. I get no errors of any kind. I am examining the returned class by both returnedObject.getClass().getName() and via Eclipse debugger.

      Anyone: Please advise as to how to get subclasses returned from em find or query????

      Here are the relevant class declarations:

      // base class
      @Table(name = "units", catalog = "test2", uniqueConstraints = @UniqueConstraint(columnNames = "unitName"))
      @DiscriminatorColumn(name="hwModel", discriminatorType=DiscriminatorType.INTEGER)
      // 1st subclass
      @DiscriminatorColumn(discriminatorType = DiscriminatorType.INTEGER)
      public class RFUnit extends Units {

      // 2nd subclass
      @DiscriminatorColumn(name="hwModel", discriminatorType = DiscriminatorType.INTEGER)
      public class EMUnit extends RFUnit {

      // code doing find/fetch
      UnitsList ul = new UnitsList(); // Seam convenience class
      List l = ul.getResultList();

      for (Units u:l)
      String tmp = u.getClass().getName();

      I also tried:

      ul.getEntityManager().createQuery("Select units from Units units").getResultList(); to do the fetch. Same result.

      This should be simple. What am I missing?
      I did confirm the discriminator column values where as specified in the @DiscriminatorValue annotation.