@sergeya
I tried your example code, but unfortunetly is doesn't work,
maybe you can give me an additional hint?
Code:
ArrayList<DetachedCriteria> qualCrits = new ArrayList<DetachedCriteria>();
Iterator<QualificationCriteria> minQualsIt = minQuals.iterator();
while (minQualsIt.hasNext()) {
QualificationCriteria crit = minQualsIt.next();
DetachedCriteria empCrit = DetachedCriteria.forClass(Employee.class);
DetachedCriteria qualCrit = empCrit.createCriteria("qualifications");
DetachedCriteria skillCrit = qualCrit.createCriteria("skill");
DetachedCriteria levelCrit = qualCrit.createCriteria("level");
skillCrit.add(Expression.eq("name", crit.getSkillName()));
levelCrit.add(Expression.ge("rating", crit.getMinLevelRating()));
qualCrits.add(empCrit);
}
Criteria mainCrit = session.createCriteria(Employee.class);
Iterator<DetachedCriteria> qualCritIt = qualCrits.iterator();
while (qualCritIt.hasNext()) {
mainCrit.add(Subqueries.in("userName", qualCritIt.next()));
}
return (Collection<Employee>)mainCrit.list();
I get following stack:
Code:
java.lang.NullPointerException
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getProjectedTypes(CriteriaQueryTranslator.java:298)
at org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:56)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:314)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:85)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1310)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:300)
at de.mf.pm.Helper.findEmployeesByQualifications(Helper.java:74)
at de.mf.pm.TestQuery.runAux(TestQuery.java:24)
at de.mf.pm.HibernateBase.run(HibernateBase.java:25)
at de.mf.pm.TestQuery.main(TestQuery.java:41)
Maybe one error is usage of subqueries, i am not really sure, that 'userName' is the right parameter...
DetachedCriteria work - I have tested it by calling
Code:
empCrit.getExecutableCriteria(session).list();