-->
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.  [ 3 posts ] 
Author Message
 Post subject: Incomplete children collection with a Disjunction criteria
PostPosted: Wed Mar 14, 2007 1:06 pm 
Newbie

Joined: Mon Jul 17, 2006 12:53 pm
Posts: 5
Hello

The hibernate version I use is : 3.2.1.

I have a problem when I perform a criteria which contains OR restrictions on a collection. The root object I retrieved has its collection of children objects incomplete. Only the children which correspond to the OR restrictions are in the collection but the other not.

Let's take the following example. The class A has got a Set<B> of the class B.

Code:
// Population step
A a1 = new A();
a1.setName("a1");
for (int i = 0; i < 5; i++) {
    B b = new B();
    b.setName("b" + i);
    // bidirectionnal relation
    b.setA(a1);
    a1.getBs().add(b);
}

// There is a cascade all to save the attached Bs
session.save(a1);
session.flush();
session.clear();

// Test
Criteria criteria = session.createCriteria(A.class);
Disjunction disjunction = Restrictions.disjunction();
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
criteria.createAlias("bs", "bs", CriteriaSpecification.LEFT_JOIN);
//criteria.createAlias("bs", "bs");
int i = 0;
for(B b : a1.getBs()){
    i++;
    if (i < 4){
        disjunction.add(Restrictions.eq("bs.name", b.getName()));
    }
}
criteria.add(disjunction);
List<A> as = criteria.list();
assertEquals(1, as.size());
A a2 = as.get(0);
assertEquals(5, a2.getBs().size());



The last assertion fails. In fact, in the a2.bs (Set<B>), there are only the 3 first b. But even if the 2 last b don't correspond to the OR restrictions, I want to retrieve the whole object A with all its B.

When I do
Code:
criteria.createAlias("bs", "bs");
(default = INNER_JOIN) instead of
Code:
criteria.createAlias("bs", "bs", CriteriaSpecification.LEFT_JOIN)
, it works.

Indeed, when I do that, the collection of b is not populated and a lazy loading is performed when I do a2.getBs(). But this is not the case when I specified LEFT_JOIN. Why the behavior for populating the collection is not the same between INNER_JOIN and LEFT_JOIN. It seems that when we specify LEFT_JOIN it is like "left join fetch" instead of simple "left join".

Anyway, I really need a left join on this request and not an inner join. But the collection is incompletly populated...

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 3:58 am 
Newbie

Joined: Mon Jul 17, 2006 12:53 pm
Posts: 5
Nobody to help me ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 9:08 am 
Newbie

Joined: Mon Jul 17, 2006 12:53 pm
Posts: 5
up


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.