HHH-7808 : Some exceptions returned by LocalBindingContext.makeMappingException() are not thrown

This commit is contained in:
Gail Badner 2012-11-16 18:02:50 -08:00
parent f75c7eff59
commit 58f67d59bd
3 changed files with 16 additions and 13 deletions

View File

@ -469,7 +469,7 @@ public class Binder {
final BasicPluralAttributeElementBinding elementBinding = final BasicPluralAttributeElementBinding elementBinding =
( BasicPluralAttributeElementBinding ) attributeBinding.getPluralAttributeElementBinding(); ( BasicPluralAttributeElementBinding ) attributeBinding.getPluralAttributeElementBinding();
if ( elementBinding.getNature() != PluralAttributeElementBinding.Nature.BASIC ) { if ( elementBinding.getNature() != PluralAttributeElementBinding.Nature.BASIC ) {
bindingContext().makeMappingException( String.format( throw bindingContext().makeMappingException( String.format(
"Expected a SetBinding with an element of nature Nature.BASIC; instead was %s", "Expected a SetBinding with an element of nature Nature.BASIC; instead was %s",
elementBinding.getNature() ) ); elementBinding.getNature() ) );
} }
@ -1081,7 +1081,7 @@ public class Binder {
final String defaultJavaTypeName ) { final String defaultJavaTypeName ) {
if ( explicitTypeName == null ) { if ( explicitTypeName == null ) {
if ( hibernateTypeDescriptor.getJavaTypeName() != null ) { if ( hibernateTypeDescriptor.getJavaTypeName() != null ) {
bindingContext().makeMappingException( String.format( throw bindingContext().makeMappingException( String.format(
"Attempt to re-initialize (non-explicit) Java type name; current=%s new=%s", "Attempt to re-initialize (non-explicit) Java type name; current=%s new=%s",
hibernateTypeDescriptor.getJavaTypeName(), hibernateTypeDescriptor.getJavaTypeName(),
defaultJavaTypeName ) ); defaultJavaTypeName ) );
@ -1091,7 +1091,7 @@ public class Binder {
// Check if user-specified name is of a User-Defined Type (UDT) // Check if user-specified name is of a User-Defined Type (UDT)
final TypeDefinition typeDef = metadata.getTypeDefinition( explicitTypeName ); final TypeDefinition typeDef = metadata.getTypeDefinition( explicitTypeName );
if ( hibernateTypeDescriptor.getExplicitTypeName() != null ) { if ( hibernateTypeDescriptor.getExplicitTypeName() != null ) {
bindingContext().makeMappingException( String.format( throw bindingContext().makeMappingException( String.format(
"Attempt to re-initialize explicity-mapped Java type name; current=%s new=%s", "Attempt to re-initialize explicity-mapped Java type name; current=%s new=%s",
hibernateTypeDescriptor.getExplicitTypeName(), hibernateTypeDescriptor.getExplicitTypeName(),
explicitTypeName ) ); explicitTypeName ) );
@ -1151,7 +1151,7 @@ public class Binder {
entityIdentifier.createIdentifierGenerator( identifierGeneratorFactory, properties ); entityIdentifier.createIdentifierGenerator( identifierGeneratorFactory, properties );
if ( IdentityGenerator.class.isInstance( entityIdentifier.getIdentifierGenerator() ) ) { if ( IdentityGenerator.class.isInstance( entityIdentifier.getIdentifierGenerator() ) ) {
if ( rootEntityBinding.getPrimaryTable().getPrimaryKey().getColumnSpan() != 1 ) { if ( rootEntityBinding.getPrimaryTable().getPrimaryKey().getColumnSpan() != 1 ) {
bindingContext().makeMappingException( String.format( throw bindingContext().makeMappingException( String.format(
"ID for %s is mapped as an identity with %d columns. IDs mapped as an identity can only have 1 column.", "ID for %s is mapped as an identity with %d columns. IDs mapped as an identity can only have 1 column.",
rootEntityBinding.getEntity().getName(), rootEntityBinding.getEntity().getName(),
rootEntityBinding.getPrimaryTable().getPrimaryKey().getColumnSpan() rootEntityBinding.getPrimaryTable().getPrimaryKey().getColumnSpan()
@ -1978,7 +1978,7 @@ public class Binder {
try { try {
attributeBinding.setComparator( comparatorClass.newInstance() ); attributeBinding.setComparator( comparatorClass.newInstance() );
} catch ( Exception error ) { } catch ( Exception error ) {
bindingContext().makeMappingException( throw bindingContext().makeMappingException(
String.format( String.format(
"Unable to create comparator [%s] for attribute [%s]", "Unable to create comparator [%s] for attribute [%s]",
sortable.getComparatorName(), sortable.getComparatorName(),
@ -2223,7 +2223,7 @@ public class Binder {
final boolean isNullableByDefault, final boolean isNullableByDefault,
final boolean isDefaultAttributeName ) { final boolean isDefaultAttributeName ) {
if ( columnSource.getName() == null && defaultName == null ) { if ( columnSource.getName() == null && defaultName == null ) {
bindingContext().makeMappingException( "Cannot resolve name for column because no name was specified and default name is null." ); throw bindingContext().makeMappingException( "Cannot resolve name for column because no name was specified and default name is null." );
} }
final String name; final String name;
if ( StringHelper.isNotEmpty( columnSource.getName() ) ) { if ( StringHelper.isNotEmpty( columnSource.getName() ) ) {
@ -2619,7 +2619,7 @@ public class Binder {
final EntitySource entitySource = entitySourcesByName.get( entityName ); final EntitySource entitySource = entitySourcesByName.get( entityName );
if ( entitySource == null ) { if ( entitySource == null ) {
String msg = log.missingEntitySource( entityName ); String msg = log.missingEntitySource( entityName );
bindingContext().makeMappingException( msg ); throw bindingContext().makeMappingException( msg );
} }
// Get super entity binding (creating it if necessary using recursive call to this method) // Get super entity binding (creating it if necessary using recursive call to this method)

View File

@ -399,8 +399,8 @@ public class HibernateTypeHelper {
resolvedHibernateType.isEntityType() resolvedHibernateType.isEntityType()
? EntityType.class.cast( resolvedHibernateType ).getIdentifierOrUniqueKeyType( metadata ) ? EntityType.class.cast( resolvedHibernateType ).getIdentifierOrUniqueKeyType( metadata )
: resolvedHibernateType; : resolvedHibernateType;
if ( !ComponentType.class.isInstance( resolvedRelationalType ) ) { if ( !CompositeType.class.isInstance( resolvedRelationalType ) ) {
binder.bindingContext().makeMappingException( "Column number mismatch" ); // todo refine the exception message throw binder.bindingContext().makeMappingException( "Column number mismatch" ); // todo refine the exception message
} }
Type[] subTypes = CompositeType.class.cast( resolvedRelationalType ).getSubtypes(); Type[] subTypes = CompositeType.class.cast( resolvedRelationalType ).getSubtypes();
for ( int i = 0; i < subTypes.length; i++ ) { for ( int i = 0; i < subTypes.length; i++ ) {

View File

@ -320,10 +320,13 @@ public class AssociationAttribute extends MappedAttribute {
targetTypeName = targetEntityValue.asClass().name().toString(); targetTypeName = targetEntityValue.asClass().name().toString();
} }
if( StringHelper.isEmpty( targetTypeName ) && referencedAttributeType!=null ){ if( StringHelper.isEmpty( targetTypeName ) ) {
targetTypeName = referencedAttributeType.getName(); if ( referencedAttributeType != null ) {
} else { targetTypeName = referencedAttributeType.getName();
getContext().makeMappingException( "Can't find the target type for this collection attribute: "+ getRole() ); }
else {
throw getContext().makeMappingException( "Can't find the target type for this collection attribute: "+ getRole() );
}
} }
return targetTypeName; return targetTypeName;