Skip to content

Commit

Permalink
HHH-8831 improved exception message
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
beikov authored and brmeyer committed Jan 9, 2014
1 parent 1f2e4f2 commit 3159f04
Showing 1 changed file with 9 additions and 4 deletions.
Expand Up @@ -93,6 +93,7 @@
import org.hibernate.cfg.PropertyHolderBuilder;
import org.hibernate.cfg.PropertyInferredData;
import org.hibernate.cfg.PropertyPreloadedData;
import org.hibernate.cfg.RecoverableException;
import org.hibernate.cfg.SecondPass;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.internal.CoreMessageLogger;
Expand Down Expand Up @@ -1330,9 +1331,13 @@ private static void bindCollectionSecondPass(
boolean cascadeDeleteEnabled,
XProperty property,
Mappings mappings) {
BinderHelper.createSyntheticPropertyReference(
joinColumns, collValue.getOwner(), collectionEntity, collValue, false, mappings
);
try {
BinderHelper.createSyntheticPropertyReference(
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 );
if ( property.isAnnotationPresent( ElementCollection.class ) && joinColumns.length > 0 ) {
joinColumns[0].setJPA2ElementCollection( true );
Expand Down Expand Up @@ -1444,4 +1449,4 @@ public void setMapKeyManyToManyColumns(Ejb3JoinColumn[] mapJoinColumns) {
public void setLocalGenerators(HashMap<String, IdGenerator> localGenerators) {
this.localGenerators = localGenerators;
}
}
}

0 comments on commit 3159f04

Please sign in to comment.