I am using Hibernate 2.1.2 with Resin 2.1.12 on SAPDB 7.4.
I have been trying to stay away from HQL as much as possible and accomplish as much as I can using Criteria. I have an object that has the following structure.
Code:
public class UserGroupFunction
{
...
private UserGroup userGroup = null;
private Function function = null;
...
}
public class UserGroup
{
private Long userGroupId = null;
...
}
private class Function
{
private Long functionId = null;
private String functionName = "";
private String functionUrl = "";
}
The mappings in UserGroupFunction are as follows:
Code:
<many-to-one name="userGroup" class="com.foo.bar.beans.site.access.UserGroup" cascade="none" outer-join="false" update="false" insert="true" column="USERGROUPID" not-null="true" unique="false" />
<many-to-one name="function" class="com.foo.bar.beans.site.access.Function" cascade="none" outer-join="true" update="false" insert="true" column="FUNCTIONID" not-null="true" unique="false" />
In the search() method in my DAO, I would like to accomplish two conditionals.
1. WHERE function.functionUrl IS NOT NULL
2. ORDER BY function.functionName
I tried to do it with the following code (out of desparation) but obviously it was too stupid and didn't work.
Code:
criteria.add(Expression.not(Expression.eq("function.functionUrl", null)));
criteria.addOrder(Order.asc("function.functionName"));
Is there any way to set conditions based on attributes within an object contained in the persistent object using the Criteria method or do I have to resign myself to doing this with HQL?
TIA