improve some error messages
This commit is contained in:
parent
90c767681e
commit
c718a46285
|
@ -9,7 +9,6 @@ package org.hibernate.boot.model.internal;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.AnnotationException;
|
import org.hibernate.AnnotationException;
|
||||||
import org.hibernate.MappingException;
|
|
||||||
import org.hibernate.annotations.Check;
|
import org.hibernate.annotations.Check;
|
||||||
import org.hibernate.annotations.ColumnDefault;
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
import org.hibernate.annotations.ColumnTransformer;
|
import org.hibernate.annotations.ColumnTransformer;
|
||||||
|
@ -779,8 +778,9 @@ public class AnnotatedColumn {
|
||||||
final ColumnDefault columnDefault =
|
final ColumnDefault columnDefault =
|
||||||
getOverridableAnnotation( property, ColumnDefault.class, getBuildingContext() );
|
getOverridableAnnotation( property, ColumnDefault.class, getBuildingContext() );
|
||||||
if ( columnDefault != null ) {
|
if ( columnDefault != null ) {
|
||||||
if ( length!=1 ) {
|
if ( length != 1 ) {
|
||||||
throw new MappingException("@ColumnDefault may only be applied to single-column mappings");
|
throw new AnnotationException( "'@ColumnDefault' may only be applied to single-column mappings but '"
|
||||||
|
+ property.getName() + "' maps to " + length + " columns" );
|
||||||
}
|
}
|
||||||
setDefaultValue( columnDefault.value() );
|
setDefaultValue( columnDefault.value() );
|
||||||
}
|
}
|
||||||
|
@ -797,7 +797,8 @@ public class AnnotatedColumn {
|
||||||
getOverridableAnnotation( property, GeneratedColumn.class, getBuildingContext() );
|
getOverridableAnnotation( property, GeneratedColumn.class, getBuildingContext() );
|
||||||
if ( generatedColumn != null ) {
|
if ( generatedColumn != null ) {
|
||||||
if (length!=1) {
|
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() );
|
setGeneratedAs( generatedColumn.value() );
|
||||||
}
|
}
|
||||||
|
@ -812,8 +813,9 @@ public class AnnotatedColumn {
|
||||||
if ( property != null ) {
|
if ( property != null ) {
|
||||||
final Check check = getOverridableAnnotation( property, Check.class, getBuildingContext() );
|
final Check check = getOverridableAnnotation( property, Check.class, getBuildingContext() );
|
||||||
if ( check != null ) {
|
if ( check != null ) {
|
||||||
if (length!=1) {
|
if ( length != 1 ) {
|
||||||
throw new MappingException("@Check may only be applied to single-column mappings (use a table-level @Check)");
|
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() );
|
setCheckConstraint( check.constraints() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,12 @@ import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.loader.internal.AliasConstantsHelper;
|
import org.hibernate.loader.internal.AliasConstantsHelper;
|
||||||
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
||||||
import org.hibernate.sql.Template;
|
|
||||||
import org.hibernate.type.spi.TypeConfiguration;
|
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.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}
|
* A mapping model object representing a SQL {@linkplain org.hibernate.annotations.Formula formula}
|
||||||
|
@ -42,8 +44,8 @@ public class Formula implements Selectable, Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTemplate(Dialect dialect, TypeConfiguration typeConfiguration, SqmFunctionRegistry registry) {
|
public String getTemplate(Dialect dialect, TypeConfiguration typeConfiguration, SqmFunctionRegistry registry) {
|
||||||
final String template = Template.renderWhereStringTemplate( formula, dialect, typeConfiguration, registry );
|
final String template = renderWhereStringTemplate( formula, dialect, typeConfiguration, registry );
|
||||||
return safeInterning( StringHelper.replace( template, "{alias}", Template.TEMPLATE ) );
|
return safeInterning( replace( template, "{alias}", TEMPLATE ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -91,6 +93,6 @@ public class Formula implements Selectable, Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.getClass().getSimpleName() + "( " + formula + " )";
|
return getClass().getSimpleName() + "( " + formula + " )";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,12 @@ import java.util.StringTokenizer;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
|
||||||
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
|
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
|
||||||
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
||||||
import org.hibernate.type.spi.TypeConfiguration;
|
import org.hibernate.type.spi.TypeConfiguration;
|
||||||
|
|
||||||
|
import static org.hibernate.internal.util.StringHelper.WHITESPACE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses SQL fragments specified in mapping documents.
|
* Parses SQL fragments specified in mapping documents.
|
||||||
*
|
*
|
||||||
|
@ -100,7 +101,7 @@ public final class Template {
|
||||||
Dialect dialect,
|
Dialect dialect,
|
||||||
TypeConfiguration typeConfiguration,
|
TypeConfiguration typeConfiguration,
|
||||||
SqmFunctionRegistry functionRegistry) {
|
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()
|
String symbols = new StringBuilder()
|
||||||
.append( "=><!+-*/()',|&`" )
|
.append( "=><!+-*/()',|&`" )
|
||||||
.append( StringHelper.WHITESPACE )
|
.append( WHITESPACE )
|
||||||
.append( dialect.openQuote() )
|
.append( dialect.openQuote() )
|
||||||
.append( dialect.closeQuote() )
|
.append( dialect.closeQuote() )
|
||||||
.toString();
|
.toString();
|
||||||
|
|
Loading…
Reference in New Issue