criteria.add(Restrictions.eq("legalEntity", legalEntity).ignoreCase());
criteria.add(Restrictions.eq("organizationUnit", organizationUnit).ignoreCase());
// DetachedCriteria criteria =
// DetachedCriteria.forClass(GruppoDatiFinanziari.class);
Disjunction ors = Restrictions.disjunction();
for (SearchCriteriaLogicProduct sclp : andCriteriaList) {
DetachedCriteria datifinCriteria = null;
// DetachedCriteria mutuoCriteria = null;
// Conjunction andsDatifin = Restrictions.conjunction();
// Conjunction andsMutuo = null;
Conjunction andsDatifin = null;
Conjunction andsMutuo = Restrictions.conjunction();
for (SearchCriteria sc : sclp.getSearchCriteriaList()) {
SimpleExpression simpleExpression = sc.getSimpleExpression();
if (sc.getValore() instanceof String)
simpleExpression.ignoreCase();
if (((SearchCriteriaWithEntity) sc).getEntity() == GruppoDatiFinanziari.class) {
// Aggiungo condizioni di and alla subquery dei mutui
if (datifinCriteria == null) {
datifinCriteria = DetachedCriteria.forClass(GruppoDatiFinanziari.class);
datifinCriteria.setProjection(Projections.property("mutuo"));
}
if (andsDatifin == null) {
andsDatifin = Restrictions.conjunction();
}
andsDatifin.add(simpleExpression);
} else if (((SearchCriteriaWithEntity) sc).getEntity() == Mutuo.class) {
// Aggiungo condizioni di and sui Datifin
andsMutuo.add(simpleExpression);
}
if (andsDatifin != null) {
andsDatifin.add(Restrictions.isNull("dataFineValidita"));
datifinCriteria.add(andsDatifin);
andsMutuo.add(Subqueries.propertyIn("numeroMutuo", datifinCriteria));
}
ors.add(andsMutuo);
}
criteria.add(ors);
}