So there are two differences :
- the first is that I don’t know the exhaustive list of referenced types
- the second is that some types are only known at runtime (defined in another JAR).
I had implemented this solution → Lots of @AnyDiscriminatorValue - Hibernate ORM - Hibernate to solve these two problems.
Which I was able to eliminate with the implementation of DefaultDiscriminatorConverter → HHH-16339 - Consolidate DiscriminatorType, DiscriminatorMetadata, MetadataTpe by sebersole · Pull Request #6286 · hibernate/hibernate-orm (github.com)
However, the hashCode of the roles still needed to be resolved.