-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Master/detail: filtering details, get master (noob)
PostPosted: Mon Mar 28, 2011 8:53 am 
Newbie

Joined: Thu Mar 24, 2011 6:28 am
Posts: 4
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.