I have a table with a few bits of data and a varchar column called deleted that contains a single character 'Y' or 'N', or null, in the case where
for some reason or other nothing has been inserted yet.
I am using the Criteria object to create the query like so:
Code:
Session session = HibernateUtil.currentSession();
Criteria crit = session.createCriteria(TypeVOPS.class);
if(vo.getCategory() != null)
{
crit.add(Restrictions.eq("category", vo.getCategory()));
}
if(vo.getCode() != null)
{
crit.add(Restrictions.eq("code", vo.getCode()));
}
if(vo.getDescription() != null)
{
crit.add(Restrictions.eq("description", vo.getDescription()));
}
if (vo.getDeleted() != null && !vo.getDeleted().booleanValue())
{
crit.add(Restrictions.ne("deleted", Boolean.TRUE));
}
else
{
crit.add(Restrictions.eq("deleted", Boolean.TRUE));
}
crit.addOrder(Order.asc("code"));
types = crit.list();
The generated SQL (show_sql=true):Code:
SELECT this_.type_id AS type1_0_, this_.category_id AS category2_40_0_,
this_.code AS code40_0_, this_.description AS descript4_40_0_,
this_.deleted AS deleted40_0_,
this_.short_description AS short6_40_0_
FROM hill.tbl_type_ps this_
WHERE this_.category_id = 18 AND this_.deleted='N'
ORDER BY this_.code ASC;
Is it possible to get something like this?:Code:
SELECT this_.type_id AS type1_0_, this_.category_id AS category2_40_0_,
this_.code AS code40_0_, this_.description AS descript4_40_0_,
this_.deleted AS deleted40_0_,
this_.short_description AS short6_40_0_
FROM hill.tbl_type_ps this_
WHERE this_.category_id = 18 AND NVL(this_.deleted, 'N') = 'N'
ORDER BY this_.code ASC;
Thanks,