1 Reply Latest reply on Jan 7, 2007 7:28 AM by Alex Grönholm

    EJB QL - Inheritence Query Question

    Crayton OSteen Newbie

      Assume the following environment:

      I have a base abstract class setup for inheritence that has a Many-to-Many relationship with another class like:

      @Entity
      @Inheritance(strategy = InheritanceType.JOINED)
      public abstract class Automobile implements Serializable
      {
       private Set<Part> parts;
      
       @ManyToMany(mappedBy="parts")
       public Set<Part> getParts()
       {
       return parts;
       }
      }
      
      @Entity
      public class Part implements Serializable
      {
       private Set<Automobile> autos;
      
       @ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
       public Set<Automobile> getAutomobiles()
       {
       return autos;
       }
      }
      
      
      


      I have two classes that derive from my base calss.
      @Entity
      public class Car extends Automobile
      
      @Entity
      public class Truck extends Automobile
      



      Can a EJB QL query be constructed such that I only get results for one of the derived classes?

      Something like:

      for this part get only the "Cars" associated with it.

      SELECT auto FROM Autobile auto, IN(auto.parts) AS part where part=:specificPart and "Automobile instanceof Car"