2
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-jpamodelgen</artifactId>
        <version>6.0.0.Alpha2</version>
    </dependency>

When I add hibernate-jpamodelgen dependency to the project. Everything works properly until the compilation process. I can see generated metamodel classes under target folder. But because of my system defaults (that are related to my operating system), the field name constants on metamodel classes are converted wrong.

public static final String TRANST�ME = "transtime";
public static final String NOTE = "note";
public static final String �SACT�VE = "isactive";

-

[ERROR] /C:/Users/*/IdeaProjects/*/target/generated-sources/annotations/*/model/acc/InvtypeView_.java:[20,37] illegal character: '\ufffd'

And that causes a compile error. When I analyzed the code generation process I can see org.hibernate.jpamodelgen.util.StringUtil classes' getUpperUnderscoreCaseFromLowerCamelCase method causes this.

public static String getUpperUnderscoreCaseFromLowerCamelCase(String lowerCamelCaseString){
    return lowerCamelCaseString.replaceAll("(.)(\\p{Upper})", "$1_$2").toUpperCase();
}

toUpperCase method should have parameter Locale.ROOT.

I've created an issue on Hibernate issue tracker system.

Any quick solution/workaround would be great.

alan
  • 48
  • 1
  • 13
Erce Tilav
  • 1,073
  • 1
  • 12
  • 20
  • I understand the problem stems from using one of the variants of the non-ASCII Turkish 'i' character. From my experience, even though Java as a language supports Unicode, I often find that the tooling does not, so I would recommend to avoid using non-Latin characters for identifiers. Otherwise, you may manage to fix your issue only to find that another tool is having problems – crizzis Jul 24 '19 at 12:19
  • What method do you use to get the metamodel classes generated? There are usages with Ant, and multiple ways of doing it by Maven: https://docs.jboss.org/hibernate/orm/5.0/topical/html/metamodelgen/MetamodelGenerator.html - over compiler or processor plugin. Depending on the method you use, you might find a way to pass the Locale variables to the compiler & compile processor, and you wouldn't need to change your system settings. – Utku Özdemir Jul 24 '19 at 12:23
  • 1
    @crizzis I'm not using any Turkish character in my code. The problem is that code generator converting "transtime" field as TRANSTİME constant name, not TRANSTIME. – Erce Tilav Jul 24 '19 at 12:23
  • @UtkuÖzdemir I'm just adding dependency to my POM. See docs: "In most cases the annotation processor will automatically run provided the processor jar is added to the build classpath and a JDK >6 is used. This happens due to Java’s Service Provider contract and the fact the the Hibernate Static Metamodel Generator jar files contains the file javax.annotation.processing.Processor in the META-INF/services directory." – Erce Tilav Jul 24 '19 at 12:28
  • @evracle In that case, you are probably facing [this issue](http://java.sys-con.com/node/46241), where the dotted *i* becomes capitalized as *İ*. You may try fixing that issue by using the `-Duser.language=en` flag or the `en` tag to force capitalization of *i* into *I* – crizzis Jul 24 '19 at 14:22
  • I'm having this issue too(when running `mvn compile`), and only solution i've found is to change my OS's(Win10) lang setting to English. Pom.xml changes below did not work for me. – Kambaa Sep 09 '22 at 14:54

3 Answers3

2

I have fixed the same problem with following configuration.

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>${java.version}</source>
        <target>${java.version}</target>
        <fork>true</fork>
        <compilerArgs>
            <compilerArg>-J-Duser.language=en</compilerArg>
            <compilerArg>-J-Duser.country=US</compilerArg>
            <compilerArg>-J-Dfile.encoding=UTF-8</compilerArg>
        </compilerArgs>
        <annotationProcessorPaths>
            <annotationProcessorPath>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-jpamodelgen</artifactId>
                <version>${hibernate.version}</version>
            </annotationProcessorPath>
        </annotationProcessorPaths>
    </configuration>
</plugin>
Ghokun
  • 3,345
  • 3
  • 26
  • 30
  • It worked after I set fork option to true. See: https://maven.apache.org/plugins-archives/maven-compiler-plugin-3.8.1/compile-mojo.html#compilerArgs If you update your answer, I can select it as correct. – Erce Tilav Aug 17 '19 at 09:05
1

UPDATE MARCH-2023:

Adding .mvn/jvm.config file in your project with contents -Duser.country=US -Duser.language=en seems to change the locale for the maven, this seems to be the better approach.

UPDATE FEB-2023:

After some debugging, Below is my findings about this problem:

https://prnt.sc/6_MhLRmJkfMv

even if nothing's wrong with my entity(encoding-wise) JpaMetaModelGen's StringUtils class method uses toUpperCase() method which uses JVM's default Locale for uppercase operation. Here are some documentation on upperCase method:

This method is locale sensitive, and may produce unexpected results if used for strings that are intended to be interpreted locale independently. Examples are programming language identifiers, protocol keys, and HTML tags. For instance, "title".toUpperCase() in a Turkish locale returns "T\u0130TLE", where '\u0130' is the LATIN CAPITAL LETTER I WITH DOT ABOVE character. To obtain correct results for locale insensitive strings, use toUpperCase(Locale.ROOT).

it seems like i need to change my JVM locale to english (normally when you call java command you need to add these jvm args: -Duser.country=US -Duser.language=en ) to make this problem go away, but adding these to mvn command did not worked for me, so in IDEA i did this and it seemed to worked.

IDEA Maven Locale Change JVM Commands

Some links on JVM Locale

I'm having this issue right now(when running maven compile, it gives me this problem not idea's run configurations, weird! ), and only solution i've found is to change my OS's(Win10) lang setting to English. Pom.xml changes above did not work for me.

Kambaa
  • 467
  • 3
  • 8
0

I had the same problems. My problem was solved with the following plugins

<plugin>
            <inherited>true</inherited>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin.version}</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <compilerArgument>-proc:none</compilerArgument>
                <encoding>UTF-8</encoding>
                <showWarnings>true</showWarnings>
                <showDeprecation>true</showDeprecation>

            </configuration>
        </plugin>

        <plugin>
            <groupId>org.bsc.maven</groupId>
            <artifactId>maven-processor-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <phase>generate-sources</phase>
                    <configuration>
                        <compilerArguments>-AaddGeneratedAnnotation=false</compilerArguments> <!-- suppress java.annotation -->
                        <processors>
                            <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                        </processors>
                        <outputDirectory>generated</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
sss
  • 11
  • 1