@Any and @ManyToAny Associations Fail in Spring Boot 3

Yes, I saw that other post, however it doesn’t indicate for sure they are using Spring. I’ll reply to that one with a link to this comment.

I have created two repositories on GitHub containing the sample projects I mentioned above. One is using Spring Boot 2.7.11 (Hibernate 5.6.15.Final) while the other uses Spring Boot 3.0.6 (Hibernate 6.1.7.Final). They both contain the example classes from their respective Hibernate documentation for @Any and @ManyToAny associations and a single test class containing the tests from that documentation. Running a diff -r on them will show the only difference between the two repositories is the Spring Boot version and how the @Any relations are setup:

This is all you need to do to reproduce the failure using a Java 17 SDK:

git clone https://github.com/dirkniblick/polymorphOnSpringBoot2.git
cd polymorphOnSpringBoot2/
gradle test --info
cd ..
git clone https://github.com/dirkniblick/polymorphOnSpringBoot3.git
cd polymorphOnSpringBoot3/
gradle test --info

You will see the first one pass and the second one fail:

> Task :test FAILED

HibernatePolymorphApplicationTests > createPropertyRepository() FAILED
    java.lang.NullPointerException: Cannot invoke "org.hibernate.metamodel.mapping.AttributeMapping.getAttributeMetadataAccess()" because the return value of "org.hibernate.sql.results.graph.Fetchable.asAttributeMapping()" is null