I trying to build a Criteria made up of various components. Imagine the mapped classes below.
class Thing {
Inner inner;
String x;
}
class User {
Id; // mapped as id.
String first; // indexed columns etc
String last;
}
I would like to create a query (aka Criterion) for Things where User.first=@1 and User.last=@2. I can easily achieve this by creating sub criteria off the root for the User and then adding the Restrictions to this.
Critera root = ...
root.add( Restrictions.eq( "xxx", @2 ));
Criteria user = root.createCritera("user");
user.add( Restrictions.eq("first", @1));
...etc
However i cannot create an AND for a property of thing and user using code similar to ...
Critera root = ...
root.add( Restrictions.and( Restrictions.eq("user.first", @1), Restrictions.eq("thing.x", @2));
A QueryException is thrown that "user.first" is not an association. The need to manually create criteria before adding the restriction seems something that should not be necessary but yet it is.. Attempts to use alias in the second form also fail.