Skip to content

Commit 58f67d5

Browse files
committed
HHH-7808 : Some exceptions returned by LocalBindingContext.makeMappingException() are not thrown
1 parent f75c7ef commit 58f67d5

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ private void bindBasicSetCollectionTablePrimaryKey(final SetBinding attributeBin
469469
final BasicPluralAttributeElementBinding elementBinding =
470470
( BasicPluralAttributeElementBinding ) attributeBinding.getPluralAttributeElementBinding();
471471
if ( elementBinding.getNature() != PluralAttributeElementBinding.Nature.BASIC ) {
472-
bindingContext().makeMappingException( String.format(
472+
throw bindingContext().makeMappingException( String.format(
473473
"Expected a SetBinding with an element of nature Nature.BASIC; instead was %s",
474474
elementBinding.getNature() ) );
475475
}
@@ -1081,7 +1081,7 @@ private void bindHibernateTypeDescriptor(
10811081
final String defaultJavaTypeName ) {
10821082
if ( explicitTypeName == null ) {
10831083
if ( hibernateTypeDescriptor.getJavaTypeName() != null ) {
1084-
bindingContext().makeMappingException( String.format(
1084+
throw bindingContext().makeMappingException( String.format(
10851085
"Attempt to re-initialize (non-explicit) Java type name; current=%s new=%s",
10861086
hibernateTypeDescriptor.getJavaTypeName(),
10871087
defaultJavaTypeName ) );
@@ -1091,7 +1091,7 @@ private void bindHibernateTypeDescriptor(
10911091
// Check if user-specified name is of a User-Defined Type (UDT)
10921092
final TypeDefinition typeDef = metadata.getTypeDefinition( explicitTypeName );
10931093
if ( hibernateTypeDescriptor.getExplicitTypeName() != null ) {
1094-
bindingContext().makeMappingException( String.format(
1094+
throw bindingContext().makeMappingException( String.format(
10951095
"Attempt to re-initialize explicity-mapped Java type name; current=%s new=%s",
10961096
hibernateTypeDescriptor.getExplicitTypeName(),
10971097
explicitTypeName ) );
@@ -1151,7 +1151,7 @@ private void bindIdentifierGenerator(final EntityBinding rootEntityBinding) {
11511151
entityIdentifier.createIdentifierGenerator( identifierGeneratorFactory, properties );
11521152
if ( IdentityGenerator.class.isInstance( entityIdentifier.getIdentifierGenerator() ) ) {
11531153
if ( rootEntityBinding.getPrimaryTable().getPrimaryKey().getColumnSpan() != 1 ) {
1154-
bindingContext().makeMappingException( String.format(
1154+
throw bindingContext().makeMappingException( String.format(
11551155
"ID for %s is mapped as an identity with %d columns. IDs mapped as an identity can only have 1 column.",
11561156
rootEntityBinding.getEntity().getName(),
11571157
rootEntityBinding.getPrimaryTable().getPrimaryKey().getColumnSpan()
@@ -1978,7 +1978,7 @@ private void bindSortingAndOrdering(
19781978
try {
19791979
attributeBinding.setComparator( comparatorClass.newInstance() );
19801980
} catch ( Exception error ) {
1981-
bindingContext().makeMappingException(
1981+
throw bindingContext().makeMappingException(
19821982
String.format(
19831983
"Unable to create comparator [%s] for attribute [%s]",
19841984
sortable.getComparatorName(),
@@ -2223,7 +2223,7 @@ private Column createColumn(
22232223
final boolean isNullableByDefault,
22242224
final boolean isDefaultAttributeName ) {
22252225
if ( columnSource.getName() == null && defaultName == null ) {
2226-
bindingContext().makeMappingException( "Cannot resolve name for column because no name was specified and default name is null." );
2226+
throw bindingContext().makeMappingException( "Cannot resolve name for column because no name was specified and default name is null." );
22272227
}
22282228
final String name;
22292229
if ( StringHelper.isNotEmpty( columnSource.getName() ) ) {
@@ -2619,7 +2619,7 @@ private EntityBinding findOrBindingEntityBinding(final String entityName) {
26192619
final EntitySource entitySource = entitySourcesByName.get( entityName );
26202620
if ( entitySource == null ) {
26212621
String msg = log.missingEntitySource( entityName );
2622-
bindingContext().makeMappingException( msg );
2622+
throw bindingContext().makeMappingException( msg );
26232623
}
26242624

26252625
// Get super entity binding (creating it if necessary using recursive call to this method)

hibernate-core/src/main/java/org/hibernate/metamodel/internal/HibernateTypeHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ public void bindJdbcDataType(Type resolvedHibernateType, List<RelationalValueBin
399399
resolvedHibernateType.isEntityType()
400400
? EntityType.class.cast( resolvedHibernateType ).getIdentifierOrUniqueKeyType( metadata )
401401
: resolvedHibernateType;
402-
if ( !ComponentType.class.isInstance( resolvedRelationalType ) ) {
403-
binder.bindingContext().makeMappingException( "Column number mismatch" ); // todo refine the exception message
402+
if ( !CompositeType.class.isInstance( resolvedRelationalType ) ) {
403+
throw binder.bindingContext().makeMappingException( "Column number mismatch" ); // todo refine the exception message
404404
}
405405
Type[] subTypes = CompositeType.class.cast( resolvedRelationalType ).getSubtypes();
406406
for ( int i = 0; i < subTypes.length; i++ ) {

hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,13 @@ private String determineReferencedEntityType(AnnotationInstance associationAnnot
320320
targetTypeName = targetEntityValue.asClass().name().toString();
321321
}
322322

323-
if( StringHelper.isEmpty( targetTypeName ) && referencedAttributeType!=null ){
324-
targetTypeName = referencedAttributeType.getName();
325-
} else {
326-
getContext().makeMappingException( "Can't find the target type for this collection attribute: "+ getRole() );
323+
if( StringHelper.isEmpty( targetTypeName ) ) {
324+
if ( referencedAttributeType != null ) {
325+
targetTypeName = referencedAttributeType.getName();
326+
}
327+
else {
328+
throw getContext().makeMappingException( "Can't find the target type for this collection attribute: "+ getRole() );
329+
}
327330
}
328331

329332
return targetTypeName;

0 commit comments

Comments
 (0)