Hibernate 返回编码错误的字符串
Hibernate returning string with bad encoding
当我使用 Hibernate 在我的数据库中获取实体时,returned 字符串的编码很差。数据库是Oracle 11g。
示例:
2015.2 Ajout d’un point de contrôle
被return编辑为:
2015.2 Ajout d\u0092un point de contrôle
我在 hibernate.cfg.xml 中尝试了一些设置:
<property name="hibernate.connection.defaultNChar">true</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.CharSet">utf-16</property>
<property name="hibernate.connection.characterEncoding">utf-16</property>
但是没有成功。
这里是数据库设置:
NLS_CHARACTERSET WE8MSWIN1252
NLS_NCHAR_CHARACTERSET AL16UTF16
包含数据的行描述为 VARCHAR2(255 Bytes)
如何才能 return 正确编码我的实体的字符串?
这看起来数据在插入数据库之前是错误的。 \u0092
不是 Unicode 中的有效代码点,但它存在于 Windows-1252 (CP1252) 中。这表明有人将使用 Windows 编码的数据插入数据库,而不是首先将字符转换为正确的 Unicode。
此类问题的常见来源是当您在未指定编码的情况下读取文本文件时,或者当您依赖平台默认字符集将 encoding/decoding 字节转换为字符串时。
当我使用 Hibernate 在我的数据库中获取实体时,returned 字符串的编码很差。数据库是Oracle 11g。
示例:
2015.2 Ajout d’un point de contrôle
被return编辑为:
2015.2 Ajout d\u0092un point de contrôle
我在 hibernate.cfg.xml 中尝试了一些设置:
<property name="hibernate.connection.defaultNChar">true</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.CharSet">utf-16</property>
<property name="hibernate.connection.characterEncoding">utf-16</property>
但是没有成功。
这里是数据库设置:
NLS_CHARACTERSET WE8MSWIN1252
NLS_NCHAR_CHARACTERSET AL16UTF16
包含数据的行描述为 VARCHAR2(255 Bytes)
如何才能 return 正确编码我的实体的字符串?
这看起来数据在插入数据库之前是错误的。 \u0092
不是 Unicode 中的有效代码点,但它存在于 Windows-1252 (CP1252) 中。这表明有人将使用 Windows 编码的数据插入数据库,而不是首先将字符转换为正确的 Unicode。
此类问题的常见来源是当您在未指定编码的情况下读取文本文件时,或者当您依赖平台默认字符集将 encoding/decoding 字节转换为字符串时。