In the end, the cause of this problem seems to be a bug in Hibernate 6.2.6.Final. This is the version included in Wildfly 29. I ran the same test with Wildfly 35 and Hibernate 6.6.8.Final and it worked fine.