-->
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: Vagueness with multicalling join function for From interface
PostPosted: Mon Mar 21, 2011 6:16 am 
Newbie

Joined: Sun Oct 17, 2010 7:54 am
Posts: 5
Hi.

Let us suppose we have a class Building which have a set of another classes Floors. We want to get the Building and its first floor. So our code may be like this:
Code:
   CriteriaBuilder builder = em.getCriteriaBuilder();
   CriteriaQuery<Tuple> cr = builder.createTupleQuery();

   Root<Building> root = cr.from(Building.class);
        Join<?, ?> join = root.join("floors");
        cr.where(builder.equal(join.get("number"), 1));
        cr.multiselect(root, join);


This code works perfect, because we get SQL query like this:
Code:
     [java] Hibernate:
     [java]     select
     [java]         building0_.beanId as beanId0_0_,
     [java]         floors1_.beanId as beanId0_1_,
     [java]         building0_.description as descript2_0_0_,
     [java]         building0_.UUID as UUID0_0_,
     [java]         building0_.name as name0_0_,
     [java]         building0_.address as address2_0_,
     [java]         floors1_.description as descript2_0_1_,
     [java]         floors1_.UUID as UUID0_1_,
     [java]         floors1_.name as name0_1_,
     [java]         floors1_.building_beanId as building3_1_1_,
     [java]         floors1_.number as number1_1_
     [java]     from
     [java]         Building building0_
     [java]     inner join
     [java]         Floor floors1_
     [java]             on building0_.beanId=floors1_.building_beanId
     [java]     where
     [java]         floors1_.number=1



But if our code like this:

Code:
   CriteriaBuilder builder = em.getCriteriaBuilder();
   CriteriaQuery<Tuple> cr = builder.createTupleQuery();

   Root<Building> root = cr.from(Building.class);
        Join<?, ?> join = root.join("floors");
        cr.where(builder.equal(root.join("floors").get("number"), 1));
        cr.multiselect(root, join);


We get wrong result of query (Building with ALL floors), because SQL code is:
Code:
     [java] Hibernate:
     [java]     select
     [java]         building0_.beanId as beanId0_0_,
     [java]         floors1_.beanId as beanId0_1_,
     [java]         building0_.description as descript2_0_0_,
     [java]         building0_.UUID as UUID0_0_,
     [java]         building0_.name as name0_0_,
     [java]         building0_.address as address2_0_,
     [java]         floors1_.description as descript2_0_1_,
     [java]         floors1_.UUID as UUID0_1_,
     [java]         floors1_.name as name0_1_,
     [java]         floors1_.building_beanId as building3_1_1_,
     [java]         floors1_.number as number1_1_
     [java]     from
     [java]         Building building0_
     [java]     inner join
     [java]         Floor floors1_
     [java]             on building0_.beanId=floors1_.building_beanId
     [java]     inner join
     [java]         Floor floors2_
     [java]             on building0_.beanId=floors2_.building_beanId
     [java]     where
     [java]         floors2_.number=1



Is behaivour of second code expected?

P.S.: If this is bug I can provide TestCase for Hibernate, if any.


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.