[jboss-user] [EJB 3.0] - EJB QL - Inheritence Query Question

costeen21 do-not-reply at jboss.com
Fri Jan 5 12:01:47 EST 2007


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"



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3998321#3998321

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3998321



More information about the jboss-user mailing list