gpt4 book ai didi

java - SQL错误: 1366 Incorrect integer value Spring MVC Hibernate

转载 作者:行者123 更新时间:2023-12-01 15:05:53 25 4
gpt4 key购买 nike

当我尝试使用 Springs 默认存储库保存对象时,我无法弄清楚为什么有些东西不起作用。我使用 hibernate 作为持久层和 Spring MVC 框架。我使用 JPA 而不是 hibernate 映射文件。

我看到的错误如下:

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;
}

上面的代码解决了问题

关于java - SQL错误: 1366 Incorrect integer value Spring MVC Hibernate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12966144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com