So far I have some code that does not really do what I want it to do:
Criteria criteria = session.createCriteria(Entry.class)
.add(
Expression.or(
Expression.or(Expression.like("title","%"+term+"%"),Expression.like("description","%"+term+"%"))
,Expression.like("comment","%"+term+"%")));
What I would like to do is something like:
Criteria criteria = session.createCriteria(Entry.class);
if ( searchTitle ) { criteria.addOr(Expression.like("title","%"+term+"%")) }
if ( searchDescription ) { criteria.addOr(Expression.like("description","%"+term+"%")) }
if ( searchComment ) { criteria.addOr(Expression.like("comment","%"+term+"%")) }
I suppose I could create the HQL myself, but I was hoping for something that looked a bit cleaner, where I wouldn't have to check whether a previous condition had already been added.
Is this possible? I am looking into this myself, but if someone could save me their time with their knowledge then it would be appreciated.
|