From d0a7a017a501e726ac9bd22c029bdc76418160ef Mon Sep 17 00:00:00 2001 From: ammachado Date: Wed, 13 Mar 2013 14:42:39 -0300 Subject: [PATCH] HHH-8068 Suggestion for improvement. --- .../hql/internal/ast/tree/ConstructorNode.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/ConstructorNode.java b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/ConstructorNode.java index a277b31ddd..fd9fbdb45b 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/ConstructorNode.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/ConstructorNode.java @@ -39,6 +39,7 @@ import org.hibernate.internal.util.StringHelper; import org.hibernate.transform.AliasToBeanConstructorResultTransformer; import org.hibernate.transform.ResultTransformer; import org.hibernate.transform.Transformers; +import org.hibernate.type.PrimitiveType; import org.hibernate.type.Type; /** @@ -184,10 +185,23 @@ public class ConstructorNode extends SelectExpressionList implements AggregatedS catch ( PropertyNotFoundException e ) { // this is the exception returned by ReflectHelper.getConstructor() if it cannot // locate an appropriate constructor - throw new DetailedSemanticException( "Unable to locate appropriate constructor on class [" + className + "]", e ); + String formattedMessage = formatMissingContructorExceptionMessage(className); + throw new DetailedSemanticException( formattedMessage, e ); } } + private String formatMissingContructorExceptionMessage(String className) { + String[] params = new String[constructorArgumentTypes.length]; + for ( int j = 0; j < constructorArgumentTypes.length; j++ ) { + params[j] = constructorArgumentTypes[j] instanceof PrimitiveType ? + ( ( PrimitiveType ) constructorArgumentTypes[j] ).getPrimitiveClass().getName() : + constructorArgumentTypes[j].getReturnedClass().getName(); + } + String formattedList = params.length == 0 ? "no arguments constructor" : StringHelper.join(", ", params); + return String.format( "Unable to locate appropriate constructor on class [%s]. Expected types are: %s", + className, formattedList ); + } + public Constructor getConstructor() { return constructor; }