diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java index 77c50fcf98..eb36e3da6a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java @@ -9,7 +9,6 @@ package org.hibernate.boot.model.internal; import java.util.Map; import org.hibernate.AnnotationException; -import org.hibernate.MappingException; import org.hibernate.annotations.Check; import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.ColumnTransformer; @@ -779,8 +778,9 @@ public class AnnotatedColumn { final ColumnDefault columnDefault = getOverridableAnnotation( property, ColumnDefault.class, getBuildingContext() ); if ( columnDefault != null ) { - if ( length!=1 ) { - throw new MappingException("@ColumnDefault may only be applied to single-column mappings"); + if ( length != 1 ) { + throw new AnnotationException( "'@ColumnDefault' may only be applied to single-column mappings but '" + + property.getName() + "' maps to " + length + " columns" ); } setDefaultValue( columnDefault.value() ); } @@ -797,7 +797,8 @@ public class AnnotatedColumn { getOverridableAnnotation( property, GeneratedColumn.class, getBuildingContext() ); if ( generatedColumn != null ) { if (length!=1) { - throw new MappingException("@GeneratedColumn may only be applied to single-column mappings"); + throw new AnnotationException("'@GeneratedColumn' may only be applied to single-column mappings but '" + + property.getName() + "' maps to " + length + " columns" ); } setGeneratedAs( generatedColumn.value() ); } @@ -812,8 +813,9 @@ public class AnnotatedColumn { if ( property != null ) { final Check check = getOverridableAnnotation( property, Check.class, getBuildingContext() ); if ( check != null ) { - if (length!=1) { - throw new MappingException("@Check may only be applied to single-column mappings (use a table-level @Check)"); + if ( length != 1 ) { + throw new AnnotationException("'@Check' may only be applied to single-column mappings but '" + + property.getName() + "' maps to " + length + " columns (use a table-level '@Check')" ); } setCheckConstraint( check.constraints() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Formula.java b/hibernate-core/src/main/java/org/hibernate/mapping/Formula.java index 9533982fda..a80dcf54a1 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Formula.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Formula.java @@ -13,10 +13,12 @@ import org.hibernate.dialect.Dialect; import org.hibernate.internal.util.StringHelper; import org.hibernate.loader.internal.AliasConstantsHelper; import org.hibernate.query.sqm.function.SqmFunctionRegistry; -import org.hibernate.sql.Template; import org.hibernate.type.spi.TypeConfiguration; +import static org.hibernate.internal.util.StringHelper.replace; import static org.hibernate.internal.util.StringHelper.safeInterning; +import static org.hibernate.sql.Template.TEMPLATE; +import static org.hibernate.sql.Template.renderWhereStringTemplate; /** * A mapping model object representing a SQL {@linkplain org.hibernate.annotations.Formula formula} @@ -42,8 +44,8 @@ public class Formula implements Selectable, Serializable { @Override public String getTemplate(Dialect dialect, TypeConfiguration typeConfiguration, SqmFunctionRegistry registry) { - final String template = Template.renderWhereStringTemplate( formula, dialect, typeConfiguration, registry ); - return safeInterning( StringHelper.replace( template, "{alias}", Template.TEMPLATE ) ); + final String template = renderWhereStringTemplate( formula, dialect, typeConfiguration, registry ); + return safeInterning( replace( template, "{alias}", TEMPLATE ) ); } @Override @@ -91,6 +93,6 @@ public class Formula implements Selectable, Serializable { @Override public String toString() { - return this.getClass().getSimpleName() + "( " + formula + " )"; + return getClass().getSimpleName() + "( " + formula + " )"; } } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/Template.java b/hibernate-core/src/main/java/org/hibernate/sql/Template.java index 7e7c93b783..5ed0b13f26 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/Template.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/Template.java @@ -15,11 +15,12 @@ import java.util.StringTokenizer; import org.hibernate.HibernateException; import org.hibernate.dialect.Dialect; -import org.hibernate.internal.util.StringHelper; import org.hibernate.query.sqm.function.SqmFunctionDescriptor; import org.hibernate.query.sqm.function.SqmFunctionRegistry; import org.hibernate.type.spi.TypeConfiguration; +import static org.hibernate.internal.util.StringHelper.WHITESPACE; + /** * Parses SQL fragments specified in mapping documents. * @@ -100,7 +101,7 @@ public final class Template { Dialect dialect, TypeConfiguration typeConfiguration, SqmFunctionRegistry functionRegistry) { - return renderWhereStringTemplate(sqlWhereString, TEMPLATE, dialect, typeConfiguration, functionRegistry); + return renderWhereStringTemplate( sqlWhereString, TEMPLATE, dialect, typeConfiguration, functionRegistry ); } /** @@ -128,7 +129,7 @@ public final class Template { String symbols = new StringBuilder() .append( "=>