亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Hibernate JPA 2 Metamodel Generator Turkish Char問題

Hibernate JPA 2 Metamodel Generator Turkish Char問題

慕蓋茨4494581 2023-04-13 17:22:47
   <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 問題跟蹤器系統上創建了一個問題。任何快速解決方案/解決方法都會很棒。
查看完整描述

3 回答

?
繁花不似錦

TA貢獻1851條經驗 獲得超4個贊

我用以下配置解決了同樣的問題。


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


查看完整回答
反對 回復 2023-04-13
?
守候你守候我

TA貢獻1802條經驗 獲得超10個贊

2023 年 3 月更新:

在您的項目中添加包含內容的.mvn/jvm.config文件-Duser.country=US -Duser.language=en似乎會更改 Maven 的語言環境,這似乎是更好的方法。

2023 年 2 月更新:

經過一些調試,下面是我對這個問題的發現:

http://img4.sycdn.imooc.com/6437ca1c00013c8323530817.jpg

即使我的實體(編碼方式)沒有問題,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 中我這樣做了,它似乎起作用了。

http://img2.sycdn.imooc.com/6437ca2800011b6421430688.jpg


查看完整回答
反對 回復 2023-04-13
?
墨色風雨

TA貢獻1853條經驗 獲得超6個贊

我有同樣的問題。我的問題已通過以下插件解決


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


查看完整回答
反對 回復 2023-04-13
  • 3 回答
  • 0 關注
  • 186 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號