<p>I'm not sure how to describe this problem, so I think an example is the best way to ask my question:</p>

<p>I have two tables with a manyToMany relationship:</p>

<p>DriversLicence &lt;-> LicenceClass</p>

<p>LicenceClass is things like "Car", "Motorbike", and "Medium Rigid".</p>

<p>Using Hibernate Criteria, how can I find all licences that have both "Car" and "Motorbike" LicenceClasses?</p>

<p>UPDATE 12/11/2008
I have discovered that this can easily be achieved by using a custom ResultTransformer. However the problem is that a result transformer only gets applied AFTER the query returns its results, it does not actually become part of the SQL. So I guess my question is now "Can you do what I initially described in SQL - and is there a Hibernate Criteria analog?"</p>

You can still use dot notation to work across the relations.  For example, assuming you have a DriversLicence.licenceClass property and LicenceClass.type property, then:
```
```
session.createCriteria(DriversLicence.class)
   .add(Expression.or(
     Expression.eq("licenceClass.type", "Car"),
     Expression.eq("licenceClass.type", "Motorbike")
   )
).list();
```
```
Personally though, I'd simply avoid using criteria in this case because it's not a dynamic query, but instead use:
```
```
session.createQuery("from DriversLicence where licenceClass.type in (:types)")
  .setParameterList("types", myListOfTypes)
  .list();
```
```