From bee9ea6ae0764c2da500081bc77c3cbe67d18916 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Thu, 23 Mar 2023 10:34:22 +0100 Subject: [PATCH] HHH-16355 Fix check for binding inverse many to many foreign key --- .../org/hibernate/boot/model/internal/CollectionBinder.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java index fad3a55d84..47122b2cd9 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java @@ -2615,7 +2615,9 @@ public abstract class CollectionBinder { AnnotatedJoinColumns joinColumns, SimpleValue value, boolean unique) { - if ( isUnownedCollection() ) { + // This method is also called for entity valued map keys, so we must consider + // the mappedBy of the join columns instead of the collection's one + if ( joinColumns.hasMappedBy() ) { bindUnownedManyToManyInverseForeignKey( targetEntity, joinColumns, value ); } else {