-->
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: How to SubSelect in Where clause?
PostPosted: Tue Jan 02, 2007 10:36 am 
Newbie

Joined: Tue Nov 28, 2006 9:34 am
Posts: 15
Location: Brasil
This code:
Code:
         Criteria criteria = getSession().createCriteria(Solicita.class, "solicita");
         criteria.setProjection(Projections.property("solicita.numero"));
         criteria.add(Restrictions.eq("solicita.flgAprov", (byte)1));
         
         Criteria subCriteria = getSession().createCriteria(InicCart.class, "iniccart");
         subCriteria.createAlias("iniccart.solicita", "solicita");
         subCriteria.setProjection(Projections.property("solicita.pkSolicita"));
         criteria.add(Restrictions.not(Restrictions.in("solicita.pkSolicita", subCriteria.list().toArray())));
         
         criteria.setMaxResults(1);
         return (Integer)criteria.uniqueResult();


Results in:
Code:
Hibernate:
    select
        solicita1_.PkSolicita as y0_
    from
        iniccart this_
    inner join
        solicita solicita1_
            on this_.FkSolicita=solicita1_.PkSolicita
Hibernate:
    select
        this_.Numero as y0_
    from
        solicita this_
    where
        this_.FlgAprov=?
        and not (this_.PkSolicita in (?, ?, ?, ?)) limit ?


Nice, but, something like this is already very enough:
Quote:
select
this_.Numero as y0_
from
solicita this_
where
this_.FlgAprov=?
and not (this_.PkSolicita in (select FkSolicita from iniccart)) limit ?


Is there any how?

Thanks!


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.