I have a named query in my hbm file. I would like to have some of the parameters optional so that if they aren't provided in the parameter map/ array of parameter objects then it is not included inthe where clause.
I have the query below. I would like to be able to leave off Area so the where clause becomes:
(fooTable.fooTablePK.Facility = :Facility
AND fooTable.fooTablePK.Unit = :Unit
AND fooTable.OpSystem = :OpSystem
AND fooTable.Division = :Division
AND fooTable.SystemCode = :SystemCode
AND fooTable.PClass = :PClass)
What is the best way to do this in Hibernate?
Thanks,
brian_a_lee@hotmail.com
Hibernate version:
2
Mapping documents:
SELECT fooTable
FROM com.nothingcorp.server.data.dao.FooTable fooTable
WHERE
(fooTable.fooTablePK.Facility = :Facility
AND fooTable.fooTablePK.Unit = :Unit
AND fooTable.OpSystem = :OpSystem
AND fooTable.Division = :Division
AND fooTable.Area = :Area
AND fooTable.SystemCode = :SystemCode
AND fooTable.PClass = :PClass)
ORDER BY
fooTable.fooTablePK.Facility,
fooTable.fooTablePK.Unit,
fooTable.fooTablePK.ShutdownNbr,
fooTable.fooTablePK.ShutdownDateFrom,
fooTable.fooTablePK.ShutdownDateTo
Code between sessionFactory.openSession() and session.close():
Query q = s.getNamedQuery(name);
if (null != params) {
for (Iterator i=params.entrySet().iterator(); i.hasNext(); ) {
Map.Entry entry = (Map.Entry) i.next();
setParameterValue(q, (String) entry.getKey(), entry.getValue());
}
}
return q.list()
Name and version of the database you are using:
Oracle 9.2.1