【问题标题】:Eclipselink characterEncoding equivalenceEclipselink 字符编码等价
【发布时间】:2011-10-26 12:16:58
【问题描述】:

我在 JPA 中遇到问题 - EclipseLink 字符编码问题。我的项目的 persistent.xml 是 ;

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="jpa-1" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>com.usta.jpa1.KITAPLAR</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/dBase"/>
      <property name="javax.persistence.jdbc.password" value="app"/>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="javax.persistence.jdbc.user" value="app"/>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

但是,我运行我的应用程序,将对象保存到我的数据库中,然后我的土耳其字符无法正确显示。我想将编码字符集更改为 UTF-8。我找到了;

<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding" value="UTF-8" />

然后找不到 eclipseLink 等价物

【问题讨论】:

    标签: jpa character-encoding eclipselink


    【解决方案1】:

    看起来 EclipseLink 确实没有用于编码的实现特定配置参数:

    http://www.eclipse.org/eclipselink/api/2.2/org/eclipse/persistence/config/PersistenceUnitProperties.html

    但是,请确保您的项目以 UTF-8 格式编译。检查 Eclipse 是否配置正确:Window->Preferences->General->Workspace text file encoding is UTF-8。此外,如果是这种情况,请将您的 Maven 项目配置为也以 UTF-8 编译:

    http://maven.apache.org/general.html

    【讨论】:

    • 谢谢,我的 ide 是 Netbeans,我的 netbeans 项目的编码类型是 UTF-8 但源代码/二进制格式是 1.5,我的 jdk 是 1.6,我把它改成 1.6 然后它正确运行
    • 我也有同样的问题。我通过将连接 URL 附加为 jdbc:mysql://host:port/dbName?useUnicode=true&characterEncoding=UTF-8 来解决它
    猜你喜欢
    • 1970-01-01
    • 2014-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多