views:

24

answers:

0

I'm using query by example and I have an object which has two child objects. The problem I have is I want to make a query which has limitations for both child tables and I cant work out how you do it. When I do this:

List results = session.createCriteria(Cat.class)
     .add( Example.create(cat) )
         .createCriteria("owner")
     .add( Example.create( cat.getOwner() ) )
         .createCriteria("catType")
     .add( Example.create( cat.getType() ) )
     .list();

Both owner and catType are child objects of cat:


<class name="Cat">
     <id name="id" column="catId">
         <generator class="native"/>
     </id>
     <many-to-one name="owner"
         column="ownerId"
     not-null="true"/>
     <many-to-one name="catType"
         column="catTypeId"
         not-null="true"/>
</class>

<class name="Owner">
     <id name="id" column="ownerId">
         <generator class="native"/>
     </id>
</class>

<class name="CatType">
     <id name="id" column="catTypeId">
         <generator class="native"/>
     </id>
</class>

It says owner doesn't have a field catType, is there any way I can make two criteria on the root table and merge them?