From 58f67d59bd6bd0bc82a36e80d0706aea5210dd4d Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Fri, 16 Nov 2012 18:02:50 -0800 Subject: [PATCH] HHH-7808 : Some exceptions returned by LocalBindingContext.makeMappingException() are not thrown --- .../org/hibernate/metamodel/internal/Binder.java | 14 +++++++------- .../metamodel/internal/HibernateTypeHelper.java | 4 ++-- .../attribute/AssociationAttribute.java | 11 +++++++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java index 2952369f4e..7af8cb3687 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java @@ -469,7 +469,7 @@ public class Binder { final BasicPluralAttributeElementBinding elementBinding = ( BasicPluralAttributeElementBinding ) attributeBinding.getPluralAttributeElementBinding(); 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", elementBinding.getNature() ) ); } @@ -1081,7 +1081,7 @@ public class Binder { final String defaultJavaTypeName ) { if ( explicitTypeName == 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", hibernateTypeDescriptor.getJavaTypeName(), defaultJavaTypeName ) ); @@ -1091,7 +1091,7 @@ public class Binder { // Check if user-specified name is of a User-Defined Type (UDT) final TypeDefinition typeDef = metadata.getTypeDefinition( explicitTypeName ); 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", hibernateTypeDescriptor.getExplicitTypeName(), explicitTypeName ) ); @@ -1151,7 +1151,7 @@ public class Binder { entityIdentifier.createIdentifierGenerator( identifierGeneratorFactory, properties ); if ( IdentityGenerator.class.isInstance( entityIdentifier.getIdentifierGenerator() ) ) { 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.", rootEntityBinding.getEntity().getName(), rootEntityBinding.getPrimaryTable().getPrimaryKey().getColumnSpan() @@ -1978,7 +1978,7 @@ public class Binder { try { attributeBinding.setComparator( comparatorClass.newInstance() ); } catch ( Exception error ) { - bindingContext().makeMappingException( + throw bindingContext().makeMappingException( String.format( "Unable to create comparator [%s] for attribute [%s]", sortable.getComparatorName(), @@ -2223,7 +2223,7 @@ public class Binder { final boolean isNullableByDefault, final boolean isDefaultAttributeName ) { 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; if ( StringHelper.isNotEmpty( columnSource.getName() ) ) { @@ -2619,7 +2619,7 @@ public class Binder { final EntitySource entitySource = entitySourcesByName.get( entityName ); if ( entitySource == null ) { 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) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/HibernateTypeHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/HibernateTypeHelper.java index 49658eef01..4facd8234a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/HibernateTypeHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/HibernateTypeHelper.java @@ -399,8 +399,8 @@ public class HibernateTypeHelper { resolvedHibernateType.isEntityType() ? EntityType.class.cast( resolvedHibernateType ).getIdentifierOrUniqueKeyType( metadata ) : resolvedHibernateType; - if ( !ComponentType.class.isInstance( resolvedRelationalType ) ) { - binder.bindingContext().makeMappingException( "Column number mismatch" ); // todo refine the exception message + if ( !CompositeType.class.isInstance( resolvedRelationalType ) ) { + throw binder.bindingContext().makeMappingException( "Column number mismatch" ); // todo refine the exception message } Type[] subTypes = CompositeType.class.cast( resolvedRelationalType ).getSubtypes(); for ( int i = 0; i < subTypes.length; i++ ) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java index 1e06fbb13f..2858a88c0d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java @@ -320,10 +320,13 @@ public class AssociationAttribute extends MappedAttribute { targetTypeName = targetEntityValue.asClass().name().toString(); } - if( StringHelper.isEmpty( targetTypeName ) && referencedAttributeType!=null ){ - targetTypeName = referencedAttributeType.getName(); - } else { - getContext().makeMappingException( "Can't find the target type for this collection attribute: "+ getRole() ); + if( StringHelper.isEmpty( targetTypeName ) ) { + if ( referencedAttributeType != null ) { + targetTypeName = referencedAttributeType.getName(); + } + else { + throw getContext().makeMappingException( "Can't find the target type for this collection attribute: "+ getRole() ); + } } return targetTypeName;