Christoph Dreis (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNjI2MzliZDQ0...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-15711?atlOrigin=eyJpIjoiNjI2Mz...
) HHH-15711 (
https://hibernate.atlassian.net/browse/HHH-15711?atlOrigin=eyJpIjoiNjI2Mz...
) ArgumentTypesValidator doesn't support enums in string functions (
https://hibernate.atlassian.net/browse/HHH-15711?atlOrigin=eyJpIjoiNjI2Mz...
)
Change By: Christoph Dreis (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
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, but I’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
(
https://hibernate.atlassian.net/browse/HHH-15711#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15711#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100210- sha1:583150f )