I like to use QBE here because it is elegant and very readable, but i also have this problem. NormativaBody and Normativa implement the lightweight pattern, and NormativaBody has the blob field.
I want search in normatives by Normativa fields but also by text in blob field of NormativaBody. So the source code i would like should be similar to:
public Collection searchByFields(NormativaBody normativa)
throws InfrastructureException {
Collection norms = null;
String body = normativa.getBody();
normativa.setBody(null);
try {
Session session = HibernateUtil.currentSession();
Criteria criteria = session.createCriteria(NormativaBody.class);
criteria.add(Example.create(normativa));
if (body != null) {
criteria.add(Expression.ilike("body", body, MatchMode.ANYWHERE));
}
criteria.list();
} catch (HibernateException ex) {
throw new InfrastructureException(ex);
}
normativa.setBody(body);
return norms;
}
But this can't work because field "body" is not know by Normativa.hbn.xml mapping file. And i use Normativa instead of NormativaBody to avoid hibernate get me normatives with the large blob field initialized.
Any suggestion?
|