From 2202487633111ca3c6df60be1b54111ec9b2ed6b Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 24 Apr 2024 14:01:40 +0200 Subject: [PATCH] HHH-17964 Hibernate using wrong column order for ElementCollection query when composite ID is present --- .../hibernate/boot/model/internal/TableBinder.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java index f27bf485cf..abcf922ca9 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java @@ -743,9 +743,10 @@ public class TableBinder { PersistentClass referencedEntity, AnnotatedJoinColumns joinColumns, SimpleValue value) { - final List idColumns = referencedEntity instanceof JoinedSubclass - ? referencedEntity.getKey().getColumns() - : referencedEntity.getIdentifier().getColumns(); + final KeyValue keyValue = referencedEntity instanceof JoinedSubclass + ? referencedEntity.getKey() + : referencedEntity.getIdentifier(); + final List idColumns = keyValue.getColumns(); for ( int i = 0; i < idColumns.size(); i++ ) { final Column column = idColumns.get(i); final AnnotatedJoinColumn firstColumn = joinColumns.getJoinColumns().get(0); @@ -767,6 +768,11 @@ public class TableBinder { } } } + if ( keyValue instanceof Component + && ( (Component) keyValue ).isSorted() + && value instanceof DependantValue ) { + ( (DependantValue) value ).setSorted( true ); + } } private static void bindUnownedAssociation(