[英]How to handle SQL state [HY000]; error code [1366]; Incorrect string value?
[英]SQL Error: 1366 Incorrect integer value Spring MVC Hibernate
我在弄清楚为什么在尝试使用Springs默认存储库持久化对象时某些东西无法正常工作时遇到了一些麻烦。 我正在使用休眠作为我的持久层和Spring MVC框架。 我使用JPA而不是休眠映射文件。
我看到的错误如下:
WARN : org.hibernate.util.JDBCExceptionReporter - SQL Error: 1366, SQLState: HY000
ERROR: org.hibernate.util.JDBCExceptionReporter - Incorrect integer value: '\xAC\xED\x00\x05sr\x00!com.kwhours.butternut.domain.Type\xCF;\xBF\xEF\x8A\x82\x87\xF1\x02\x00\x0DZ\x00\x06isLeafI\x00\x05levelL\' for column 'type_id' at row 1
我试图用JPA注释持久化一个域对象,该代码的相关部分是:
@Entity
@Table(name = "question")
public class Question implements java.io.Serializable {
private Type type;
@Column(name = "type_id")
public Type getType() {
return this.type;
}
public void setType(Type type) {
this.type = type;
}
}
我在question.type_id列上将外键约束正确设置为type.id列。 我能够用代码正确地表示所有对象,但是当我尝试使以下存储库保留该对象时,出现上述错误。
public interface QuestionRepository extends CrudRepository<Question, Long> {
public List<Question> findByDatasetInstanceId(Long datasetInstanceId);
}
所以要明确。 我可以创建一个新的问题对象,并使用存储库从数据库中检索类型对象。 我可以将questions.type设置为这个新类型的对象,但是每当我尝试使用上面的存储库保留包含该类型的问题时,都会收到该错误。 我在调试器中签出了类型对象,似乎没有任何不妥之处。 任何线索或建议都是有帮助的。 这看起来像某种转义字符序列,但我不确定。
所以我真的很傻。 我缺少适当的注释,并且没有取出类型ID插入,而是尝试以某种方式插入此java对象
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "type_id")
public Type getType() {
return this.type;
}
上面的代码解决了这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.