From ee8b43a1beac13272303f816534df9f1e2f585e3 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Sun, 5 Jan 2025 20:45:54 +0100 Subject: [PATCH] HHH-19011 two extra fixes - make 'on' work properly for foreign keys - throw when no column name matches 'on' (cherry picked from commit 3344f3a1d19faf350c1596a324c0b11c3222dd38) --- .../binder/internal/CommentBinder.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/binder/internal/CommentBinder.java b/hibernate-core/src/main/java/org/hibernate/binder/internal/CommentBinder.java index af1fbb59b9b0..148962b76215 100644 --- a/hibernate-core/src/main/java/org/hibernate/binder/internal/CommentBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/binder/internal/CommentBinder.java @@ -43,21 +43,25 @@ else if ( value instanceof Collection ) { if ( on.isEmpty() || table.getName().equalsIgnoreCase( on ) ) { table.setComment( text ); } - // but if 'on' is explicit, it can go on a column - Value element = collection.getElement(); - for ( Column column : element.getColumns() ) { - if ( column.getName().equalsIgnoreCase( on ) ) { - column.setComment( text ); + else { + // but if 'on' is explicit, it can go on a column + for ( Column column : table.getColumns() ) { + if ( column.getName().equalsIgnoreCase( on ) ) { + column.setComment( text ); + return; + } } + throw new AnnotationException( "No matching column for '@Comment(on=\"" + on + "\")'" ); } - //TODO: list index / map key columns } else { for ( Column column : value.getColumns() ) { if ( on.isEmpty() || column.getName().equalsIgnoreCase( on ) ) { column.setComment( text ); + return; } } + throw new AnnotationException( "No matching column for '@Comment(on=\"" + on + "\")'" ); } } @@ -70,12 +74,16 @@ public void bind(Comment comment, MetadataBuildingContext context, PersistentCla if ( on.isEmpty() || primary.getName().equalsIgnoreCase( on ) ) { primary.setComment( text ); } - // but if 'on' is explicit, it can go on a secondary table - for ( Join join : entity.getJoins() ) { - Table secondary = join.getTable(); - if ( secondary.getName().equalsIgnoreCase( on ) ) { - secondary.setComment( text ); + else { + // but if 'on' is explicit, it can go on a secondary table + for ( Join join : entity.getJoins() ) { + Table secondary = join.getTable(); + if ( secondary.getName().equalsIgnoreCase( on ) ) { + secondary.setComment( text ); + return; + } } + throw new AnnotationException( "No matching column for '@Comment(on=\"" + on + "\")'" ); } }