Skip to content

Commit

Permalink
HHH-19011 two extra fixes
Browse files Browse the repository at this point in the history
- make 'on' work properly for foreign keys
- throw when no column name matches 'on'

(cherry picked from commit 3344f3a)
  • Loading branch information
gavinking authored and beikov committed Jan 16, 2025
1 parent 38d4fe6 commit ee8b43a
Showing 1 changed file with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "\")'" );
}
}

Expand All @@ -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 + "\")'" );
}
}

Expand Down

0 comments on commit ee8b43a

Please sign in to comment.