[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-5736) Problem with "not" function of CriteriaBuilder

Hardy Ferentschik (JIRA) noreply at atlassian.com
Fri Dec 17 10:06:13 EST 2010


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5736?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Hardy Ferentschik resolved HHH-5736.
------------------------------------

       Resolution: Fixed
    Fix Version/s: 4.0.0.Alpha1
                   3.6.1

> Problem with "not" function of CriteriaBuilder
> ----------------------------------------------
>
>                 Key: HHH-5736
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5736
>             Project: Hibernate Core
>          Issue Type: Bug
>    Affects Versions: 3.6.0
>            Reporter: Vyacheslav Dimitrov
>            Assignee: Hardy Ferentschik
>             Fix For: 3.6.1, 4.0.0.Alpha1
>
>         Attachments: not.patch
>
>
> Let us suppose that we have entity "Floor" with property of "number". 
> Then we want to create query with the help of Criteria API: we want to get all floors and exclude floors with number of 2 and 3. Let us suppose that our code is:
>     CriteriaBuilder builder = em.getCriteriaBuilder();
>     CriteriaQuery<Tuple> cr = builder.createTupleQuery();
>     Root<Floor> root = cr.from(Floor.class);
>     cr.multiselect(root);
>     Predicate p1 = builder.equal(root.get("number"), new Integer(2));
>     Predicate p2 = builder.equal(root.get("number"), new Integer(3));
>     cr.where(builder.not(builder.or(p1, p2)));
> So we get query:
>      [java] Hibernate: 
>      [java]     select
>      [java]         floor0_.beanId as beanId0_,
>      [java]         floor0_.building_beanId as building3_1_,
>      [java]         floor0_.number as number1_ 
>      [java]     from
>      [java]         Floor floor0_ 
>      [java]     where
>      [java]         floor0_.number=2 
>      [java]         or floor0_.number=3
> This query is wrong. Function "not" doesn't work.
> But for query "get all floors and exlclude floor with number 2" this code works:
>     CriteriaBuilder builder = em.getCriteriaBuilder();
>     CriteriaQuery<Tuple> cr = builder.createTupleQuery();
>     Root<ru.petrsu.nest.son.Floor> root = cr.from(ru.petrsu.nest.son.Floor.class);
>     cr.multiselect(root);
>     Predicate p = builder.equal(root.get("number"), new Integer(2));
>     cr.where(builder.not(p));
> We get correct query:
>      [java] Hibernate: 
>      [java]     select
>      [java]         floor0_.beanId as beanId0_,
>      [java]         floor0_.building_beanId as building3_1_,
>      [java]         floor0_.number as number1_ 
>      [java]     from
>      [java]         Floor floor0_ 
>      [java]     where
>      [java]         floor0_.number<>3

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list