JPAStorageService readContexts fails under Hibernate 6 with "locking with DISTINCT is not supported"

Description

In porting to the Jakarta EE 9 stack in https://shibboleth.atlassian.net/browse/JPAR-186#icft=JPAR-186 I came across a place in our JPAStorageService which appears to be incompatible with Hibernate 6.0.0.Beta3, which is the current iteration for that context. It may of course get fixed, but for now our tests fail because the JPAStorageServiceTest’s tearDown method calls

List<String> contexts1 = storageService.readContexts();

The code path includes this:

// this query uses the distinct keyword, it must use optimistic locking return executeNamedQuery(manager, "JPAStorageRecord.findAllContexts", null, String.class, LockModeType.OPTIMISTIC);

The query in question does indeed include DISTINCT:

@NamedQuery(name = "JPAStorageRecord.findAllContexts", query = "SELECT distinct r.context FROM JPAStorageRecord r"),

This fails with:

java.lang.RuntimeException: java.io.IOException: java.lang.IllegalStateException: org.hibernate.query.IllegalQueryOperationException: Locking with DISTINCT is not supported!

In the dev/JPAR-186 branch, I have fixed this by adding the following to tearDown():

} catch (IOException e) { // Temporarily exclude the specific failure case found under Hibernate 6.0.0.Beta3 if (e.getCause() instanceof java.lang.IllegalStateException ise) { if (ise.getCause() instanceof org.hibernate.query.IllegalQueryOperationException ioe) { if ("Locking with DISTINCT is not supported!".equals(ioe.getMessage())) { // Ignore this one. super.tearDown(); return; } } } throw new RuntimeException(e); } super.tearDown();

If we’re removing Hibernate this won’t be an ongoing issue. We need to revisit before V5 either way.

Environment

None

Activity

Scott CantorJanuary 24, 2023 at 1:35 PM

Closing as discussed.

Rod WiddowsonJune 17, 2022 at 12:57 PM

I believe that this can now be closed “wont fix” given that ODJ-342 has been resolved.

Won't Fix

Details

Assignee

Reporter

Components

Affects versions

Created December 22, 2021 at 3:59 PM
Updated January 24, 2023 at 1:35 PM
Resolved January 24, 2023 at 1:35 PM