Skip to content

Commit f8d853b

Browse files
beikovbrmeyer
authored andcommitted
HHH-8831 improved exception message
When having @joincolumn in a @CollectionTable that do not point to valid columns, the message can be really confusing. These new lines will actually enrich the exception which is thrown that the problem appeared on a specific property of a specific class. Please include this, since it is not always clear what the actual problem is with a mapping when an exception occurs.
1 parent 770a1cb commit f8d853b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
import org.hibernate.cfg.PropertyHolderBuilder;
9393
import org.hibernate.cfg.PropertyInferredData;
9494
import org.hibernate.cfg.PropertyPreloadedData;
95+
import org.hibernate.cfg.RecoverableException;
9596
import org.hibernate.cfg.SecondPass;
9697
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
9798
import org.hibernate.internal.CoreMessageLogger;
@@ -1446,9 +1447,13 @@ private static void bindCollectionSecondPass(
14461447
boolean cascadeDeleteEnabled,
14471448
XProperty property,
14481449
Mappings mappings) {
1449-
BinderHelper.createSyntheticPropertyReference(
1450-
joinColumns, collValue.getOwner(), collectionEntity, collValue, false, mappings
1451-
);
1450+
try {
1451+
BinderHelper.createSyntheticPropertyReference(
1452+
joinColumns, collValue.getOwner(), collectionEntity, collValue, false, mappings
1453+
);
1454+
} catch(RecoverableException ex) {
1455+
throw new RecoverableException("Unable to map collection property " + property.getName() + "of class " + collectionEntity.getClassName(), ex);
1456+
}
14521457
SimpleValue key = buildCollectionKey( collValue, joinColumns, cascadeDeleteEnabled, property, mappings );
14531458
if ( property.isAnnotationPresent( ElementCollection.class ) && joinColumns.length > 0 ) {
14541459
joinColumns[0].setJPA2ElementCollection( true );

0 commit comments

Comments
 (0)