Hi,
I have upgraded a project from 5.x to 6.x and noticed that one of our queries is not working anymore.
The original one looks different and is part of a Spring-Boot app, butI’ve locally added a minimal reproducing test to {{FunctionTests}} already that looks like the following:
{noformat} @Test public void testLowerUpperFunctionsWithEnums(SessionFactoryScope scope) { scope.inTransaction( session -> { session.createQuery("select lower(e.gender) from EntityOfBasics e") .list(); session.createQuery("select upper(e.gender) from EntityOfBasics e") .list(); } ); }{noformat}
{{gender}} (more respectively its getter) has been annotated with {{@Enumerated( EnumType.STRING )}}
This test fails with the following exception
{noformat}Caused by: org.hibernate.QueryException: Parameter 1 of function lower() has type STRING, but argument is of type org.hibernate.testing.orm.domain.gambit.EntityOfBasics$Gender at app//org.hibernate.query.sqm.produce.function.ArgumentTypesValidator.throwError(ArgumentTypesValidator.java:214) at app//org.hibernate.query.sqm.produce.function.ArgumentTypesValidator.checkType(ArgumentTypesValidator.java:169) at app//org.hibernate.query.sqm.produce.function.ArgumentTypesValidator.validate(ArgumentTypesValidator.java:74) at app//org.hibernate.query.sqm.function.AbstractSqmFunctionDescriptor.generateSqmExpression(AbstractSqmFunctionDescriptor.java:104) ...{noformat}
With the following little patch this seems to be working again, but I’m not quite sure If this might be breaking in other cases I don’t know.
{noformat}--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/ArgumentTypesValidator.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/ArgumentTypesValidator.java @@ -166,6 +166,9 @@ public class ArgumentTypesValidator implements ArgumentsValidator { break; case STRING: if ( !isCharacterType(code) ) { + if (Enum.class.isAssignableFrom((Class<?>) javaType)) { + return; + } throwError(type, javaType, functionName, count); } break;{noformat}
If you feel, this is the correct solution, I’d be happy to contribute both the test and the fix.
Cheers,
Christoph |
|