From 4eb03b72a7d0dc507937d6b0db5735c455ac08b9 Mon Sep 17 00:00:00 2001 From: Erdem A Memisyazici Date: Fri, 13 Sep 2024 18:27:36 -0400 Subject: [PATCH] HHH-18598 allow only List types to control via JoinTable --- .../boot/model/internal/CollectionBinder.java | 10 +++++++++- 1 file changed, 9 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 3b60323b0e..33b63c36fb 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 @@ -2189,10 +2189,18 @@ public abstract class CollectionBinder { bindCollectionSecondPass( targetEntity, joinColumns ); + if ( isCollectionOfEntities ) { + final ClassDetails collectionClassDetails = property.getType().determineRawClass(); + final Class collectionClass = collectionClassDetails.toJavaClass(); final AnnotatedJoinColumn firstInverseJoinColumn = inverseJoinColumns.getJoinColumns().get(0); final ManyToOne element = handleCollectionOfEntities( elementType, targetEntity, hqlOrderBy ); - bindManyToManyInverseForeignKey( targetEntity, inverseJoinColumns, element, firstInverseJoinColumn.isUnique() ); + bindManyToManyInverseForeignKey( + targetEntity, + inverseJoinColumns, + element, + java.util.List.class.isAssignableFrom(collectionClass) ? firstInverseJoinColumn.isUnique() : oneToMany + ); } else if ( isManyToAny ) { handleManyToAny();