奇怪的BUG jpa映射枚举出错

mandianer 2018-03-15 11:50:57
求大神解救。。。
jpa注解枚举字段为字符串类型,persistence provider 使用hibernate,写入的时候报错:Incorrect string value: '\xAC\xED\x00\x05~r...' for column 'wordtypeen' at row 1

读取的时候报不能反序列化

mysql已经设置为utf8mb4类型,将枚举字段改为字符串类型就正常了,中英文均可。。。

@Entity
@Table(name="hotword")
public class HotWord
{
@Id
private int id;
private String value;

@Enumerated(EnumType.STRING)
@Column(name="wordtypeen")
private WordType wordType;

@ManyToOne
@JoinColumn(name="tl_id")
private TimeLine timeLine;

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public WordType getWordType() {
return wordType;
}
public void setWordType(WordType wordType) {
this.wordType = wordType;
}
public TimeLine getTimeLine() {
return timeLine;
}
public void setTimeLine(TimeLine timeLine) {
this.timeLine = timeLine;
}

}


2018-03-15T11:47:49.540+0800|信息: Hibernate: insert into timeline (month, year, id) values (?, ?, ?)
2018-03-15T11:47:49.570+0800|信息: Hibernate: insert into hotword (tl_id, value, wordtypeen, id) values (?, ?, ?, ?)
2018-03-15T11:47:49.648+0800|WARN: SQL Error: 1366, SQLState: HY000
2018-03-15T11:47:49.648+0800|ERROR: Incorrect string value: '\xAC\xED\x00\x05~r...' for column 'wordtypeen' at row 1
2018-03-15T11:47:49.649+0800|信息: HHH000010: On release of batch it still contained JDBC statements
2018-03-15T11:47:49.649+0800|ERROR: HHH000346: Error during managed flush [org.hibernate.exception.GenericJDBCException: could not execute statement]
2018-03-15T11:47:49.649+0800|警告: DTX5014: Caught exception in beforeCompletion() callback:
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute statement
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1434)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:484)
at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3190)
at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2404)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:467)
at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.beforeCompletion(JtaTransactionCoordinatorImpl.java:320)
...全文
790 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
loveunittesting 2018-04-17
  • 打赏
  • 举报
回复
得看看你的WordType是怎么定义的了
mandianer 2018-03-15
  • 打赏
  • 举报
回复
补充:将mysql中对应枚举类型的字段改为mediumblob类型数据可以进来,不过明显不合适呀。。。
mandianer 2018-03-15
  • 打赏
  • 举报
回复
没人回答么,自己顶。。
mandianer 2018-03-15
  • 打赏
  • 举报
回复
没人回答,自己顶。。。
mandianer 2018-03-15
  • 打赏
  • 举报
回复
mysql中没有其它数据,只有这一行
mandianer 2018-03-15
  • 打赏
  • 举报
回复
引用 3 楼 yys79 的回复:
垃圾数据吧,如果表里的值不是你枚举的其中一个,那读的时候很定会出错。
不是垃圾数据,insert进去枚举中的值,检索不出来,报的错是不能反序列化;关键是插入都不行,就像我上面测试的,感觉像是hibernate没有识别@Enumerated(EnumType.STRING) 注解,以默认类型tinyblob处理的枚举。
loveunittesting 2018-03-15
  • 打赏
  • 举报
回复
垃圾数据吧,如果表里的值不是你枚举的其中一个,那读的时候很定会出错。

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧