Skip to content

Commit 2d07799

Browse files
committed
HHH-19011 two extra fixes
- make 'on' work properly for foreign keys - throw when no column name matches 'on'
1 parent a0e4dc7 commit 2d07799

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

hibernate-core/src/main/java/org/hibernate/binder/internal/CommentBinder.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,25 @@ else if ( value instanceof Collection collection ) {
4040
if ( on.isEmpty() || table.getName().equalsIgnoreCase( on ) ) {
4141
table.setComment( text );
4242
}
43-
// but if 'on' is explicit, it can go on a column
44-
Value element = collection.getElement();
45-
for ( Column column : element.getColumns() ) {
46-
if ( column.getName().equalsIgnoreCase( on ) ) {
47-
column.setComment( text );
43+
else {
44+
// but if 'on' is explicit, it can go on a column
45+
for ( Column column : table.getColumns() ) {
46+
if ( column.getName().equalsIgnoreCase( on ) ) {
47+
column.setComment( text );
48+
return;
49+
}
4850
}
4951
}
50-
//TODO: list index / map key columns
5152
}
5253
else {
5354
for ( Column column : value.getColumns() ) {
5455
if ( on.isEmpty() || column.getName().equalsIgnoreCase( on ) ) {
5556
column.setComment( text );
57+
return;
5658
}
5759
}
5860
}
61+
throw new AnnotationException( "No matching column for '@Comment(on=\"" + on + "\")'" );
5962
}
6063

6164
@Override
@@ -72,7 +75,9 @@ public void bind(Comment comment, MetadataBuildingContext context, PersistentCla
7275
Table secondary = join.getTable();
7376
if ( secondary.getName().equalsIgnoreCase( on ) ) {
7477
secondary.setComment( text );
78+
return;
7579
}
80+
throw new AnnotationException( "No matching column for '@Comment(on=\"" + on + "\")'" );
7681
}
7782
}
7883

0 commit comments

Comments
 (0)