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
      @Entity
      @Table(name = "units", catalog = "test2", uniqueConstraints = @UniqueConstraint(columnNames = "unitName"))
      @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
      @DiscriminatorColumn(name="hwModel", discriminatorType=DiscriminatorType.INTEGER)
      .....
      // 1st subclass
      @Entity
      @DiscriminatorColumn(discriminatorType = DiscriminatorType.INTEGER)
      @DiscriminatorValue(value="3")
      public class RFUnit extends Units {
      .....

      // 2nd subclass
      @Entity
      @DiscriminatorColumn(name="hwModel", discriminatorType = DiscriminatorType.INTEGER)
      @DiscriminatorValue(value="7")
      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();
      System.out.println(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.