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

Christoph Gerkens (JIRA) noreply at atlassian.com
Wed Apr 7 10:15:42 EDT 2010


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
         Environment: Hibernate-Core 3.5.0-Final, all database platforms
            Reporter: Christoph Gerkens


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