合并\ xEF \ xBF \ xBD时出现异常

时间:2012-11-21 09:42:45

标签: java mysql hibernate

我正在尝试合并一个具有4个属性(ID,FIRSTNAME,LASTNAME,SCORE)的对象,使用JPA作为ORM,使用MySQL作为RDBMS,我只更新特定ID的得分并获得以下异常。

08:53:23,521 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (Thread-35) SQL Error: 1366, SQLState: HY000
08:53:23,521 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (Thread-35) Incorrect string value: '\xEF\xBF\xBD' for column 'FIRSTNAME' at row 1
08:53:23,527 INFO  [org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl] (Thread-35) HHH00010:On release of batch it still contained JDBC statements
08:53:23,527 ERROR [stderr] (Thread-35) org.springframework.orm.hibernate3.HibernateJdbcException: JDBC exception on Hibernate data access: SQLException for SQL [n/a]; SQL state [HY000]; error code [1366]; Incorrect string value: '\xEF\xBF\xBD' for column 'FIRSTNAME' at row 1; nested exception is org.hibernate.exception.GenericJDBCException: Incorrect string value: '\xEF\xBF\xBD' for column 'FIRSTNAME' at row 1
08:53:23,528 ERROR [stderr] (Thread-35)         at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:645)
08:53:23,528 ERROR [stderr] (Thread-35)         at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:102)
08:53:23,528 ERROR [stderr] (Thread-35)         at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:471)
08:53:23,528 ERROR [stderr] (Thread-35)         at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)

如何摆脱这个问题?谢谢!

编辑表格整理是utf8_general_ci

1 个答案:

答案 0 :(得分:3)

0xEF 0xBF 0xBD是U + FFFD代码点的UTF-8编码形式。当UTF-8解析器无法将字节序列解析为有效的UTF-8序列时,会发生这种情况。

从您的错误中,看起来Hibernate正在提供此无效序列。因此,您需要确定堆栈中的数据处理元素是否正在使用不正确的编码来解析数据。