NullPointerException when using case on select clause using JPA Criteria API

Description

I have a complex query created using JPA criteria API that worked on previous versions (tested on 5.3.7 and 5.2.15). It doesn't work on 5.4.0.

The query contains a select case statement inside the select clause, as this simplified example:

CriteriaBuilder cb = s.getCriteriaBuilder(); CriteriaQuery<Tuple> query = cb.createTupleQuery(); Root<TestEntity> r = query.from(TestEntity.class); CriteriaBuilder.Case<Long> case1 = cb.selectCase(); case1.when(cb.equal(r.<TestEnum>get("enumField"), cb.literal(TestEnum.VAL_1)), r.<Long>get("value")); case1.otherwise(cb.nullLiteral(Long.class)); CriteriaBuilder.Case<Long> case2 = cb.selectCase(); case2.when(cb.equal(r.<TestEnum>get("enumField"), cb.literal(TestEnum.VAL_2)), r.<Long>get("value")); case2.otherwise(cb.nullLiteral(Long.class)); query .select(cb.tuple(r.<TestEnum>get("enumField").alias("enumField"), cb.sum(case1).alias("VAL_1"), cb.sum(case2).alias("VAL_2"))) .groupBy(r.<TestEnum>get("enumField"));

The example works when using HQL:

s.createQuery("select t.enumField, sum(case when t.enumField='1' then t.value else null end), sum(case when t.enumField='2' then t.value else null end) from TestEntity t group by t.enumField")

I've attached a simple test case.

Attachments

1
  • 12 Jan 2019, 03:50 PM

Activity

Show:

Guillaume SmetJanuary 16, 2019 at 4:41 PM

Reopening as the issue is a bit different and we need to incorporate both test cases and be sure both cases are fixed.

Guillaume SmetJanuary 12, 2019 at 6:34 PM

This is a duplicate of HHH-13016.

I'm closing this one. Will move https://hibernate.atlassian.net/browse/HHH-13016#icft=HHH-13016 to 5.4.1 to see if we can come up with a fix for 5.4.1.

Fixed

Details

Assignee

Reporter

Worked in

Components

Fix versions

Affects versions

Priority

Created January 12, 2019 at 3:58 PM
Updated January 19, 2019 at 5:31 PM
Resolved January 18, 2019 at 10:55 AM

Flag notifications