Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

HHH-8068 - Provide better error messages for missing constructors in HQL / JPQL Constructor queries. #482

Closed
wants to merge 1 commit into from

2 participants

@ammachado

Provide better error messages for missing constructors in HQL / JPQL Constructor queries, including the parameters needed for the missing constructor.

@brmeyer
Collaborator

Merged, thanks!

@brmeyer brmeyer closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 19, 2013
  1. @ammachado

    Suggestion for improvement.

    ammachado authored
This page is out of date. Refresh to see the latest.
View
20 hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/ConstructorNode.java
@@ -39,6 +39,7 @@
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,9 +185,22 @@ private Constructor resolveConstructor(String path) throws SemanticException {
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;
Something went wrong with that request. Please try again.