无法将 Json 解析为 Object:JPA ManytoOne 单向
Unable to parse Json to Object : JPA ManytoOne unidirectional
我正在使用 spring 存储库中的数据,数据库是 mysql。
我有 objects Parent 和 child。关系是多对一。
child 到 Parent 的关系是单向的。我在 Parent.
中没有 child obj 列表
Parent{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id = null;
@NotNull(message = "name of user should not be null")
@Size(min=2, max=30)
private String name;
}
Child{
private String name;
@ManyToOne
private Parent parent;
}
我有一个 parent“1”,我想将它引用到新创建的 child。新 child "POST" 请求的 json 输入是
{
"name":"child name",
"parent":{
"id":1
}
}
需要帮助在新创建的 child 中关联 parent“1”。
json 格式是否需要更改?我也尝试了 "parent_id" 但仍然有错误。
因为 spring-data-rest 使用 HATEOAS。以下格式有效。
{
"name":"testname1",
"parent": "http://localhost:8080/parent/2"
}
感谢所有试图回答的人。
我正在使用 spring 存储库中的数据,数据库是 mysql。
我有 objects Parent 和 child。关系是多对一。
child 到 Parent 的关系是单向的。我在 Parent.
中没有 child obj 列表Parent{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id = null;
@NotNull(message = "name of user should not be null")
@Size(min=2, max=30)
private String name;
}
Child{
private String name;
@ManyToOne
private Parent parent;
}
我有一个 parent“1”,我想将它引用到新创建的 child。新 child "POST" 请求的 json 输入是
{
"name":"child name",
"parent":{
"id":1
}
}
需要帮助在新创建的 child 中关联 parent“1”。
json 格式是否需要更改?我也尝试了 "parent_id" 但仍然有错误。
因为 spring-data-rest 使用 HATEOAS。以下格式有效。
{
"name":"testname1",
"parent": "http://localhost:8080/parent/2"
}
感谢所有试图回答的人。