[hibernate-issues] [JIRA] (HHH-14059) Cannot use full qualified enum name which has two uppercase alphabet prefix

zheng hank (JIRA) jira at hibernate.atlassian.net
Thu Jun 4 02:08:25 EDT 2020


zheng hank ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5a38e9ca2d1a2a3819bbb0c1 ) *updated* an issue

Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNzI3YjAyYjdlNTEwNGE3NTgyN2RjNGYxY2MxM2M0NGQiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14059?atlOrigin=eyJpIjoiNzI3YjAyYjdlNTEwNGE3NTgyN2RjNGYxY2MxM2M0NGQiLCJwIjoiaiJ9 ) HHH-14059 ( https://hibernate.atlassian.net/browse/HHH-14059?atlOrigin=eyJpIjoiNzI3YjAyYjdlNTEwNGE3NTgyN2RjNGYxY2MxM2M0NGQiLCJwIjoiaiJ9 ) Cannot use full qualified enum name which has two uppercase alphabet prefix ( https://hibernate.atlassian.net/browse/HHH-14059?atlOrigin=eyJpIjoiNzI3YjAyYjdlNTEwNGE3NTgyN2RjNGYxY2MxM2M0NGQiLCJwIjoiaiJ9 )

Change By: zheng hank ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5a38e9ca2d1a2a3819bbb0c1 )

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}

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

\{code}

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]

( https://hibernate.atlassian.net/browse/HHH-14059#add-comment?atlOrigin=eyJpIjoiNzI3YjAyYjdlNTEwNGE3NTgyN2RjNGYxY2MxM2M0NGQiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14059#add-comment?atlOrigin=eyJpIjoiNzI3YjAyYjdlNTEwNGE3NTgyN2RjNGYxY2MxM2M0NGQiLCJwIjoiaiJ9 )

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.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100128- sha1:e736ab1 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200604/29bfadf3/attachment.html 


More information about the hibernate-issues mailing list