Hello,
by Criteria - how to use created Alias in Restrictions.sqlRestriction() ?
i tried this:
Code:
Criteria criteria = session.createCriteria(Transaction.class);
Criteria crl_criteria = criteria.createCriteria("currentRevisionLevel", "crl");
Criteria ttr_criteria =criteria.createCriteria("transactionType").createCriteria("revision","ttr");
criteria.add( Restrictions.sqlRestriction(crl_criteria.getAlias()+".id<"+ttr_criteria.getAlias()+".id"));
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
criteria.setProjection(Projections.projectionList().add(Projections.rowCount()));
generated sql for this criteria:Code:
SELECT count( * ) AS y0_
FROM banks_transaction this_
INNER JOIN banks_financial_transaction_type financialt2_ ON this_.transactionType = financialt2_.id
INNER JOIN banks_revision ttr3_ ON financialt2_.revision = ttr3_.id
INNER JOIN banks_revision crl1_ ON this_.currentRevisionLevel = crl1_.id
WHERE crl.id < ttr.id
alias changed in generated sql from crl to crl1_ and from ttr to ttr3_ but on where clause it does not change
thanks
john