gpt4 book ai didi

java - Spring - 仅在保存/POST 时出现 'field list' 中的未知列(但读取/GET 有效...)

转载 作者:行者123 更新时间:2023-11-29 19:28:22 26 4
gpt4 key购买 nike

我在 Spring 方面遇到了一个无法克服的问题。我向类和 MySQL 数据库添加了许多字段,但这次我不知道发生了什么。

有问题的字段是score。我可以通过 GET 检索资源,并且该字段由 API 返回,但任何修改(例如 POST new )都会抛出 MySQLSyntaxErrorException: Unknown column 'score' in 'field list'

这是我的类(class):

@Entity
@Table(name = "resources")
@Audited
@JsonPropertyOrder({"id"})
public class Resource extends ResourceSupport implements Localizable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long resourceId;

// ... other fields ...

private Double score; // <== that's the one!

public Double getScore() {
return score;
}

public void setScore(Double score) {
this.score = score;
}

// ... other getters and setters ...
}

在我的数据库中,我有一个这样定义的score字段:

CREATE TABLE `resources`  ( (...) 'score' double NOT NULL (...) )

我真的不明白字段名称如何可能匹配,但我仍然遇到异常。 我浏览了 Stack 上的所有类似线程(大约 10 个),但没有一个解决这个特定问题...

最佳答案

好的,我发现了一个问题。我使用 Hibernate Envers,这是 Spring 中的一种机制(自 2009 年起),允许您存储选定表中的记录历史记录。它自动为我的 resources 表创建 resources_aud 表。后来我将该列添加到 resource 表中,但没有添加到 resource_aud 表中。

顺便说一句,我推荐 Hibernate Envers。使用起来非常简单。您只需添加 @Audited 标签即可。

关于java - Spring - 仅在保存/POST 时出现 'field list' 中的未知列(但读取/GET 有效...),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41981541/

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