-->
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.  [ 4 posts ] 
Author Message
 Post subject: Help about associations/collections
PostPosted: Tue Sep 11, 2007 4:09 pm 
Newbie

Joined: Fri Aug 17, 2007 10:06 am
Posts: 11
The problem: I want to avoid N+1 selects

So, I try the following in my case:
Code:
List list = Sistema.getSession() 
.createCriteria(Note.class) 
     .add(Restrictions.eq("dateIn", today)) 
.setFetchMode("items", FetchMode.JOIN) 
.list();     


and change my Note.hbm to use fetch="subselect" in items.
This approach is good, it brings me all items of all notes at same time.

But I need a little thing, I need all notes but only the items with "quantity>10"

I donĀ“t know how to do this..
Thanks for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 11, 2007 5:00 pm 
Newbie

Joined: Fri Aug 17, 2007 10:06 am
Posts: 11
I change my example to:
Code:
List list = Sistema.getSession()
.createCriteria(Note.class)
     .add(Restrictions.eq("dateIn", today))
  .createCriteria("item", JoinFragment.LEFT_OUTER_JOIN)
     .add(Restrictions.ge("quantity", new Integer(10)))
.list();     


but the "quantity > 10 " is writen in the "where" clause:

Code:
select ...
left outer join ...
where
  quantity>10


when I want this in the left join clause:

Code:
select ...
  left outer join ... (.. and quantity>10)
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 12, 2007 12:51 pm 
Newbie

Joined: Fri Aug 17, 2007 10:06 am
Posts: 11
Code:
      Query q = Sistema.getSession().createQuery(
            "from GrsBeneficiario b "+
            "left join b.grsGuia g with g.tipoguia=1 "+
            "left join g.grsGuiaEvento e with e.evento in (select gee.evento from GrsGrupoeventosEvento gee) "+
            "where b.codigo >= :codigo");
      q.setString("codigo", "00000300000000009595");
      return q.list();


this code gives the error:

with-clause referenced two different from-clause elements [from previnne.GrsBeneficiario b left join b.grsGuia g with g.tipoguia=1 left join g.grsGuiaEvento e with e.evento in (select gee.evento from previnne.GrsGrupoeventosEvento gee) where b.codigo >= :codigo]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 12, 2007 1:49 pm 
Newbie

Joined: Fri Aug 17, 2007 10:06 am
Posts: 11
Hibernate is dead or this is a huge vacation?


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

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.