Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
JPAStorageService readContexts fails under Hibernate 6 with "locking with DISTINCT is not supported"
Basics
Logistics
Basics
Logistics
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
// 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:
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.
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.