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.
This commit is contained in:
Christian Beikov 2013-04-26 16:10:18 +03:00 committed by Brett Meyer
parent 553f65a360
commit 509da750fe

View File

@ -92,6 +92,7 @@
import org.hibernate.cfg.PropertyHolderBuilder; import org.hibernate.cfg.PropertyHolderBuilder;
import org.hibernate.cfg.PropertyInferredData; import org.hibernate.cfg.PropertyInferredData;
import org.hibernate.cfg.PropertyPreloadedData; import org.hibernate.cfg.PropertyPreloadedData;
import org.hibernate.cfg.RecoverableException;
import org.hibernate.cfg.SecondPass; import org.hibernate.cfg.SecondPass;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
@ -1446,9 +1447,13 @@ private static void bindCollectionSecondPass(
boolean cascadeDeleteEnabled, boolean cascadeDeleteEnabled,
XProperty property, XProperty property,
Mappings mappings) { Mappings mappings) {
try {
BinderHelper.createSyntheticPropertyReference( BinderHelper.createSyntheticPropertyReference(
joinColumns, collValue.getOwner(), collectionEntity, collValue, false, mappings joinColumns, collValue.getOwner(), collectionEntity, collValue, false, mappings
); );
} catch(RecoverableException ex) {
throw new RecoverableException("Unable to map collection property " + property.getName() + "of class " + collectionEntity.getClassName(), ex);
}
SimpleValue key = buildCollectionKey( collValue, joinColumns, cascadeDeleteEnabled, property, mappings ); SimpleValue key = buildCollectionKey( collValue, joinColumns, cascadeDeleteEnabled, property, mappings );
if ( property.isAnnotationPresent( ElementCollection.class ) && joinColumns.length > 0 ) { if ( property.isAnnotationPresent( ElementCollection.class ) && joinColumns.length > 0 ) {
joinColumns[0].setJPA2ElementCollection( true ); joinColumns[0].setJPA2ElementCollection( true );