1 Reply Latest reply on Jan 7, 2007 7:28 AM by alexg79

    EJB QL - Inheritence Query Question

    costeen21

      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"



        • 1. Re: EJB QL - Inheritence Query Question
          alexg79

           

          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"

          SELECT auto FROM Car ...
          It's that simple :)