[hibernate-issues] [Hibernate-JIRA] Commented: (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:38:43 EDT 2010
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5078?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=36223#action_36223 ]
Christoph Gerkens commented on HHH-5078:
----------------------------------------
Hibernate log output:
Hibernate: /* select distinct 2.0BD - 1.0BD / 2.0BD from hibernateBugHHH5078TestCase.SystemUser as generatedAlias0 */ select top ? distinct 2.0-(1.0/2.0) as col_0_0_ from INFORMATION_SCHEMA.SYSTEM_USERS systemuser0_
> 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