HHH-15627 fix uninformative error message

This commit is contained in:
Gavin King 2022-10-29 00:28:33 +02:00
parent ed65962fb3
commit 749e5e6b38
1 changed files with 12 additions and 10 deletions

View File

@ -139,7 +139,7 @@ public class BinderHelper {
* to need the value when it writes the association.) * to need the value when it writes the association.)
* <p> * <p>
* Complicating this hugely is the fact that an association might * Complicating this hugely is the fact that an association might
* be based on a composite key with multiple {@code @JoinColumns}, * be based on a composite key with multiple {@code @JoinColumn}s,
* and so the referenced columns might even be spread out over * and so the referenced columns might even be spread out over
* multiple fields or properties of the target entity. There's * multiple fields or properties of the target entity. There's
* even some extra minor complications resulting from multi-table * even some extra minor complications resulting from multi-table
@ -440,13 +440,15 @@ public class BinderHelper {
// specified by the @JoinColumn annotations. // specified by the @JoinColumn annotations.
final List<Column> orderedColumns = new ArrayList<>( columns.length ); final List<Column> orderedColumns = new ArrayList<>( columns.length );
final Map<Column, Set<Property>> columnsToProperty = new HashMap<>(); final Map<Column, Set<Property>> columnsToProperty = new HashMap<>();
final InFlightMetadataCollector collector = context.getMetadataCollector();
for ( AnnotatedJoinColumn joinColumn : columns ) { for ( AnnotatedJoinColumn joinColumn : columns ) {
Column column = new Column( final String referencedColumn = joinColumn.getReferencedColumn();
context.getMetadataCollector().getPhysicalColumnName( if ( isEmptyOrNullAnnotationValue( referencedColumn ) ) {
referencedTable, throw new AnnotationException("Association " + associationMessage( associatedEntity, joinColumn )
joinColumn.getReferencedColumn() + " has a '@JoinColumn' which does not specify the 'referencedColumnName'"
) + " (when an association has multiple '@JoinColumn's, they must each specify their 'referencedColumnName')");
); }
final Column column = new Column( collector.getPhysicalColumnName( referencedTable, referencedColumn ) );
orderedColumns.add( column ); orderedColumns.add( column );
columnsToProperty.put( column, new HashSet<>() ); columnsToProperty.put( column, new HashSet<>() );
} }
@ -464,7 +466,7 @@ public class BinderHelper {
} }
else { else {
// special case for entities with multiple @Id properties // special case for entities with multiple @Id properties
Component key = persistentClass.getIdentifierMapper(); final Component key = persistentClass.getIdentifierMapper();
for ( Property p : key.getProperties() ) { for ( Property p : key.getProperties() ) {
matchColumnsByProperty( p, columnsToProperty ); matchColumnsByProperty( p, columnsToProperty );
} }