求大神解救
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)

解决方案 »

  1.   

    补充:将mysql中对应枚举类型的字段改为mediumblob类型数据可以进来,不过明显不合适呀
      

  2.   


    不是垃圾数据,insert进去枚举中的值,检索不出来,报的错是不能反序列化;关键是插入都不行,就像我上面测试的,感觉像是hibernate没有识别@Enumerated(EnumType.STRING) 注解,以默认类型tinyblob处理的枚举。
      

  3.   

    mysql中没有其它数据,只有这一行
      

  4.   

    得看看你的WordType是怎么定义的了