简体   繁体   中英

Hibernate JPA 2 Metamodel Generator Turkish Char problem

    <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.

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>

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>

inttelij 想法帮助 -> 编辑自定义虚拟机选项添加行尾“-Duser.language=en -Duser.country=US”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM