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'
  • Loading branch information
gavinking committed Jan 6, 2025
1 parent cc7f705 commit 3344f3a
Showing 1 changed file with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,25 @@ else if ( value instanceof Collection 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 @@ -67,12 +71,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 3344f3a

Please # to comment.