Hi, I found that this sql will throw error: Invalid path: 'io.github.zhengyhn.practice.hibernate.ABStatus.A'.
{code:java}select s from Sample s where s.upperStatus = io.github.zhengyhn.practice.hibernate.ABStatus.A{code}
But the below sql works.
{code:java}select s from Sample s where s.lowerStatus = io.github.zhengyhn.practice.hibernate.BaStatus.A{code}
I read the code and found this is because of these lines of code in org.hibernate.internal.util.ReflectHelper.
{code:java}if ( conventionalJavaConstants && !JAVA_CONSTANT_PATTERN.matcher( name ).find() ) { return null; }{code}
And the JAVA_CONSTANT_PATTERN is as below.
{code:java}private static final Pattern JAVA_CONSTANT_PATTERN = Pattern.compile( "[a-z\\d]+\\.([A-Z]{1}[a-z\\d]+)+\\$?([A-Z]{1}[a-z\\d]+)*\\.[A-Z_\\$]+", Pattern.UNICODE_CHARACTER_CLASS);{code}
This pattern indicate that the constant name must begin with an upper case alphabet. So "ABStatus" cannot be recognized as valid constant name.
However, in my real-world project, we use GSStatus as the enum class name. I have to change it to GsStatus currently.
I suggest changing this pattern to
\ { code:java noformat }
"\ [a-z\\ \\ d] + .( \ [A-Z]+ \ [a-z\\ \\ d] + ) + \\ \\ $?( \ [A-Z] \ {1} \ [a-z\\ \\ d] + )*\\ \\ . \ [A-Z_ + + $] +".
\ { code noformat }
I have written a simple project for finding this issue. You can refer it as reference. [https://github.com/zhengyhn/java-practice/tree/master/hibernate-enum|https://github.com/zhengyhn/java-practice/tree/master/hibernate-enum] |
|