1 Reply Latest reply on Sep 1, 2005 6:43 AM by Emmanuel Bernard

    EJB QL Quering objects based on superclass members.

    Joe Williams Newbie

      I've scoured all the documentaion on EJB QL over the last few days and the only mention I've seen was part of the old EJB spec that says:

      "CMP does not support inheritance"

      But since EJB3.0 addresses this issue, I've moved to developing with it. And I am pleased.


      Here is my problem. I have the following objects:

      This code may contain errors because its from the top of my head. The code is not with me here.

      //pseudo code real code is not in front of me
      
      @Entity
      @Inheritance(strategy=StrategyType.JOINED)
      @DiscriminatorColumn(name="OBJ_TYPE")
      class MyObject {
       private String name;
       private int id;
      
       //getters setters and ORM annotations
      }
      
      @Entity
      @Inheritance (strategy=StrategyType.JOINED)
      @InheritanceDiscriminator (value="S" )
      @JoinColumn(column=@Column(name="OBJ_ID"))
      class Site extends MyObject {
       private String path;
      
      
       //getters setters and ORM annotaionts
      }
      


      I've thuroghly testing pulling the base object then verifying all the parent attributes are present.

       //this works no problem.
       em.createQuery("from Site s").getResultList();
      


      Here is the code that is troubling me.


       //problem code. This gives me an error about entity not defined.
       em.createQuery("from Site s where s.name = :name");
       em.setParameter("name", sName);
      
       return em.getResultList();
      


      I don't have the exact stack trace with me, but it seems that it will not allow me to query attributes from the super class. Am I doing this wrong, or is are queries up the inheritance chain not supported and I should seek another method.