MapKey and MapsId, JoinTable configuration looks good. I found below JOIN issue with few versions of Hibernate 6 https://hibernate.atlassian.net/browse/HHH-18086
Hibernate documention v6.2.4 https://in.relation.to/2023/06/01/hibernate-orm-624-final states
Map type associations
We have a couple bugs related to Map type associations:
Using the @MapKey annotation led to wrongly generated SQL for inserts in some cases
https://hibernate.atlassian.net/browse/HHH-16370
Hibernate 6.2.5 introduced stricter validation checks hence the assertion failure you're seeing while sorting
If the test configurations are compatible with Hibernate 6(persistence.xml or application.properties) and still tests are failing it could be a legitimate hibernate issue worth logging.