[hibernate-issues] [Hibernate-JIRA] Updated: (HHH-5078) JPA criteria query numeric expressions produce wrong result (due to wrong bracketing)

Jesper Steen Møller (JIRA) noreply at atlassian.com
Wed Apr 21 17:05:33 EDT 2010


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

Jesper Steen Møller updated HHH-5078:
-------------------------------------

    Attachment: hhh-5078-fix.txt

This patch adds the test and includes a fix, which is not optimal but will get the job done; it will bracket expressions like (((2 + 2) + 2) + 2) which is not needed, in other words, it just adds the parentheses without regards for precedence or associativity.
 
I've checked the other expression renderers and they appear safe enough, notably the conjunction and disjunction.

> JPA criteria query numeric expressions produce wrong result (due to wrong bracketing)
> -------------------------------------------------------------------------------------
>
>                 Key: HHH-5078
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5078
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: entity-manager, query-criteria
>    Affects Versions: 3.5.0-Final, 3.5.1
>         Environment: Hibernate-Core 3.5.0-Final, all database platforms
>            Reporter: Christoph Gerkens
>             Fix For: 3.5.x
>
>         Attachments: hhh-5078-fix.txt, TestCase_HHH-5078.zip
>
>
> The combination of quot and diff results in wrong SQL code. E.g.: (2 - 1) / 2 should be evaluated to 0.5 not 1.5 ( which is 2 - (1 / 2).
> JUnit 4 Test:
>   @Test
>   public void testJpaCriteriaApiQuoteAndDiff() {
>     CriteriaBuilder cb = em.getCriteriaBuilder();
>     CriteriaQuery<Number> query = cb.createQuery(Number.class);
>     query.from(SystemUser.class); // entity type doesn't matter, but must contain at least one entry for this test case. 
>     query.select( // (2 - 1) / 2
>         cb.quot(
>           cb.diff(
>             cb.literal(BigDecimal.valueOf(2.0)), 
>             cb.literal(BigDecimal.valueOf(1.0))), 
>           BigDecimal.valueOf(2.0))).distinct(true);
>     Number result = em.createQuery(query).getSingleResult();
>     assertEquals(0.5d, result.doubleValue(), 0.1d); // (2 - 1) / 2 = 0.5
>   }

-- 
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