1

Background: Java/Wildfly/Hibernate application with Java 8 and Hibernate 5.3.9.Final.

I have a named query like this

  @NamedQuery(
    name = DailyStatement.GET_EXPORT_DATES_BY_ORGASTRUCTUREIDS_FOR_MISEXPORT,
    query =
            " SELECT d.orgaStructureId, MIN(d.workingDay), MAX(d.workingDay) "
                    + "   FROM DailyStatement d "
                    + "  WHERE d.orgaStructureId in (:orgaStructureIds) "
                    + "    AND d.misExportFlag = false "
                    + "    AND d.state = net.shop.ob.ptm.types.timerecord.EDailyStatmentsState.CLOSED "
                    + "    AND d.workingDay <= :maxWorkingDay "
                    + " GROUP BY d.orgaStructureId "

When starting the application I get an error

DailyStatement.getExportDatesByOrgaStructureIdsForMISExport failed because of: org.hibernate.hql.internal.ast.QuerySyntaxException: Invalid path: 'net.shop.ob.ptm.types.timerecord.EDailyStatmentsState.CLOSED' [ SELECT d.orgaStructureId, MIN(d.workingDay), MAX(d.workingDay) FROM net.shop.ob.ptm.dm.entities.DailyStatement d WHERE d.orgaStructureId in (:orgaStructureIds) AND d.misExportFlag = false AND d.state = net.shop.ob.ptm.types.timerecord.EDailyStatmentsState.CLOSED AND d.workingDay <= :maxWorkingDay GROUP BY d.orgaStructureId ]

The referenced, allegedly erroneous enum looks like this

public enum EDailyStatmentsState {
    OPEN(0),
    ERROR(1),
    CLOSED(2);

    private int id;

    //(...)

The error does not occur if I set the hibernate parameter

hibernate.query.conventional_java_constants

to false

in persistence.xml. In blog post https://vladmihalcea.com/the-performance-penalty-of-class-forname-when-parsing-jpql-and-criteria-queries/ the meaning of this parameter is explained. I would understand the error, if the constant EDailyStatmentsState.CLOSED would not follow standard Java naming conventions, but as far as I can see, it does.

Because of performance reasons I would like to set the Hibernate option

hibernate.query.conventional_java_constants

to false and fix the root cause of the error. What could be causing this?

BTW, This question is not a duplicate of e.g. this question QuerySyntaxException with enum as the non-standard lower-case enum naming is causing the error there, unlike in my case.

1 Answer 1

1

Apparently the problem is that the validation of the classname in Hibrnate is done with the following regex in class org.hibernate.internal.util.ReflectHelper:

[a-z\d]+\.([A-Z]{1}[a-z\d]+)+\$?([A-Z]{1}[a-z\d]+)*\.[A-Z_\$]+

This causes classes with two successive uppercase letters not to validate. This is a known Hibernate bug (HHH-14059) which has been internally fixed in Hibernate by replacing the offending regex with

[a-z\d]+\.([A-Z]+[a-z\d]+)+\$?([A-Z]{1}[a-z\d]+)*\.[A-Z_\$]+

I fixed the issue with a workaround by renaming the class to contain no consecutive uppercase letters.

The issue has also been fixed in Hibernate 5.4.19.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.