Hi all,
after reading many posts, I've decided to post anyway my question, in order to view the light! XD
My goal is transform this SQL query into Hibernate Criterion:
Code:
select ud.*
from table1 ud
where exists (
select *
from table2 co --detail table
where co.COD_UB = ud.COD_UB
and co.COD_CO = ud.COD_CO
and co.IDN_DB_DO = ud.IDN_DB_DO
and co.cod_co = 'ASWYX'
)
and rownum between 0 and 20
And as a noob, I try with:
Code:
Criteria crit = getSession().createCriteria(table1.class, "z");
//binding with details of table1
crit.createCriteria("z.table2s","table2s",CriteriaSpecification.LEFT_JOIN);
crit.createCriteria("table2s.table3s","table3s",CriteriaSpecification.LEFT_JOIN); //details of table2
count = ((Long)crit.setProjection(Projections.rowCount()).uniqueResult()).intValue();
//set paging data, get first 20 rows
crit.setProjection(null);
crit.setFirstResult(0);
crit.setFetchSize(20);
crit.setMaxResults(20);
crit.add(Restrictions.eq("table2s.codCo", "ASWYX"));
crit.list();
In this case test, I need to get the first 20 record of table1, which have details with "ASWYX" value in "codCo" field of table2, but instead I got the join result, as writing:
Code:
select *
from table1 a,table2 b
where b.codA = a.cod
The XMLs are correct, but maybe I must read very well all Hib APIs.....
TIA
Seek