I’ve created test case and suggested solution as pull request 6750 . It is passing (locally) all tests on H2 and PostgreSQL.
Unfortunatelly, I can not find instructions how PR can be tested on Github under JDK 17.