【发布时间】:2021-05-16 23:50:17
【问题描述】:
这是我第一个使用 Spring Boot 的 API。我可以通过在邮递员中执行 POST 请求来进入我的数据库:
{
"id":"1",
"type":"postman",
"cycleDate":"",
"durationMiliseconds":"",
"defects":"0"
}
现在,当我发出相同的请求 (id = 2) 时,我收到 500 错误,以及来自我的 API 的以下内容:
原因:java.sql.SQLSyntaxErrorException:未知列 '字段列表'中的'cycle_date'
我对这个实体的代码如下:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Test
{
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "id", updatable = false, nullable = false)
protected int id;
@Column(name = "type", nullable = false)
protected String type;
@Column(name = "cycle_date")
@Temporal(TemporalType.TIMESTAMP)
protected Date cycleDate;
@Column(name = "duration_milliseconds")
protected int durationMilliseconds;
@Column(name = "defects")
protected int defects;
public Test()
{
}
public Test(int id, String type, Date cycleDate, int durationMilliseconds, int defects)
{
this.id = id;
this.type = type;
this.cycleDate = cycleDate;
this.durationMilliseconds = durationMilliseconds;
this.defects = defects;
}
加上 getter/setter。
我已确认我的数据库中的列名为“cycle_date”,没有任何错误。
我确实有另一个继承自这个实体的实体。该实体的目标是表示 Api 测试结果,而超类 Entity 仅表示整体测试或测试运行以及与之相关的某些数据。除了 Api 之外,还会有其他类型的测试与超类 Test 相关。
@Entity(name = "Api")
public class Api extends Test
{
@Column(name = "uri")
private String uri;
@Column(name = "request_type")
private String requestType;
@Column(name = "request_body")
private String requestBody;
@Column(name = "response_code")
private int responseCode;
@Column(name = "response_body")
private String responseBody;
public Api(int id, String type, Date cycleDate, int durationMilliseconds, int defects)
{
super(id, type, cycleDate, durationMilliseconds, defects);
}
}
如果我注释掉这个类,我会收到错误:com.mysql.cj.exceptions.WrongArgumentException: SQL String cannot be NULL
这是我使用继承的问题吗?
【问题讨论】:
标签: java spring-boot entity