Hi Girls and Boys,
I wasn't able to find what I needed in Documentation (nor could Google), so I decided to post here. I am trying to build a search for a small j2ee application, and I decided to give Query by Example feature a chance. In the documentation is described that you can set a property of an Example object, but is not considered that that property could also be an object, so here is what I tried:
Code:
AnomalyReport report1 = new AnomalyReport();
Category cat1 = new Category();
cat1.setId(2);
cat1.setValue("cat 2");
report1.setCategory(cat1);
List<AnomalyReport> result = null;
try {
Example exampleReport = Example.create(report1)
.ignoreCase()
.enableLike();
Session session = (Session) entityManager.getDelegate();
Criteria criteria = session.createCriteria(AnomalyReport.class)
.add(exampleReport);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
result = (List<AnomalyReport>) criteria.list();AnomalyReport>) criteria.list();
...
Apparently this query returns all the entries, so it is not getting just reports with category id '2' and category value cat 2".
Am I doing something wrong? Or I just missed the whole point :)
Thanks,
Nebojsa