猿问

Hibernate JPA 2 Metamodel Generator Turkish Char问题

   <dependency>

        <groupId>org.hibernate</groupId>

        <artifactId>hibernate-jpamodelgen</artifactId>

        <version>6.0.0.Alpha2</version>

    </dependency>

当我将 hibernate-jpamodelgen 依赖项添加到项目时。在编译过程之前一切正常。我可以在目标文件夹下看到生成的元模型类。但是由于我的系统默认值(与我的操作系统相关),元模型类上的字段名称常量转换错误。


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'

这会导致编译错误。当我分析代码生成过程时,我可以看到 org.hibernate.jpamodelgen.util.StringUtil 类的 getUpperUnderscoreCaseFromLowerCamelCase 方法导致了这个。


public static String getUpperUnderscoreCaseFromLowerCamelCase(String lowerCamelCaseString){

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

}

toUpperCase 方法应该有参数 Locale.ROOT。


我在Hibernate 问题跟踪器系统上创建了一个问题。


任何快速解决方案/解决方法都会很棒。


慕盖茨4494581
浏览 129回答 3
3回答

繁花不似锦

我用以下配置解决了同样的问题。<plugin>&nbsp; &nbsp; <artifactId>maven-compiler-plugin</artifactId>&nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; <source>${java.version}</source>&nbsp; &nbsp; &nbsp; &nbsp; <target>${java.version}</target>&nbsp; &nbsp; &nbsp; &nbsp; <fork>true</fork>&nbsp; &nbsp; &nbsp; &nbsp; <compilerArgs>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <compilerArg>-J-Duser.language=en</compilerArg>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <compilerArg>-J-Duser.country=US</compilerArg>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <compilerArg>-J-Dfile.encoding=UTF-8</compilerArg>&nbsp; &nbsp; &nbsp; &nbsp; </compilerArgs>&nbsp; &nbsp; &nbsp; &nbsp; <annotationProcessorPaths>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <annotationProcessorPath>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.hibernate</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>hibernate-jpamodelgen</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>${hibernate.version}</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </annotationProcessorPath>&nbsp; &nbsp; &nbsp; &nbsp; </annotationProcessorPaths>&nbsp; &nbsp; </configuration></plugin>

守候你守候我

2023 年 3 月更新:在您的项目中添加包含内容的.mvn/jvm.config文件-Duser.country=US -Duser.language=en似乎会更改 Maven 的语言环境,这似乎是更好的方法。2023 年 2 月更新:经过一些调试,下面是我对这个问题的发现:即使我的实体(编码方式)没有问题,JpaMetaModelGen 的 StringUtils 类方法使用 toUpperCase() 方法,该方法使用 JVM 的默认 Locale 进行大写操作。以下是一些关于 upperCase 方法的文档:此方法对区域设置敏感,如果用于旨在独立解释区域设置的字符串,可能会产生意外结果。示例是编程语言标识符、协议密钥和 HTML 标记。例如,土耳其语言环境中的“title”.toUpperCase() 返回“T\u0130TLE”,其中“\u0130”是带点的拉丁文大写字母 I。要获得不区分语言环境的字符串的正确结果,请使用 toUpperCase(Locale.ROOT)。似乎我需要将我的 JVM 区域设置更改为英语(通常当您调用 java 命令时,您需要添加这些 jvm args:-Duser.country=US -Duser.language=en)以解决此问题,但添加这些to mvn 命令对我不起作用,所以在 IDEA 中我这样做了,它似乎起作用了。

墨色风雨

我有同样的问题。我的问题已通过以下插件解决<plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <inherited>true</inherited>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.apache.maven.plugins</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>maven-compiler-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>${maven-compiler-plugin.version}</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <source>${java.version}</source>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <target>${java.version}</target>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <compilerArgument>-proc:none</compilerArgument>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <encoding>UTF-8</encoding>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <showWarnings>true</showWarnings>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <showDeprecation>true</showDeprecation>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; </plugin>&nbsp; &nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.bsc.maven</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>maven-processor-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <executions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <execution>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goal>process</goal>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <phase>generate-sources</phase>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <compilerArguments>-AaddGeneratedAnnotation=false</compilerArguments> <!-- suppress java.annotation -->&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <processors>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </processors>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <outputDirectory>generated</outputDirectory>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </execution>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </executions>&nbsp; &nbsp; &nbsp; &nbsp; </plugin>
随时随地看视频慕课网APP

相关分类

Java
我要回答