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: Patch
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
Assignee: Gail Badner
Fix For: 3.5.2, 3.6
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: