我想从嵌套的Entity类返回一个json。
能够使用@PostMapping值提交到mysql数据库。我有3个实体Plate,Sample和Submission,它们具有@ManyToOne和@OneToMany的关系。一旦我提交了,问题就是从数据库中以json的形式检索相同的数据
这是我的实体
public class Sample {
@Id
@GeneratedValue(strategy=GenerationType.TABLE, generator="tab")
private Long id;
private String row;
private String clientSampleId;
private String comments;
private String organismName;
private Long columnNumber;
private String tissueType;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="plate_id")
private Plate plate;
}
public class Plate {
@Id
@GeneratedValue(strategy=GenerationType.TABLE, generator="tab")
private Long id;
private String clientPlateId;
private String clientPlateBarcode;
private String sampleSubmissionFormat;
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="plate")
private List<Sample> samples;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="submission_id")
private Submission submission;
}
public class Submission {
@Id
@GeneratedValue(strategy=GenerationType.TABLE, generator="tab")
private Long id;
private Long numberOfSamples;
private String sampleType;
private String clientId;
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="submission")
private List<Plate> plates;
}
尝试检索带有submissionId键的提交,它返回一个 com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields异常。
@GetMapping(value = "/submission/{submissionId}", produces = { "application/json" })
public Submission getSubmission(@PathVariable(value = "submissionId") Long submissionId) {
return submissionRepository.findById(submissionId);
}
这是我的json提交文件,应该与@GetMapping请求相同
{
"plates": [
{
"clientPlateId": "P_2519052917_1",
"clientPlateBarcode": "P_2519052917_1",
"samples": [
{
"row": "A",
"clientSampleId": "1737",
"comments": "none",
"organismName": "Wheat",
"columnNumber": 1,
"tissueType": "leaf"
}
],
"sampleSubmissionFormat": "PLATE_96"
}
],
"numberOfSamples": 94,
"sampleType": "DNA",
"clientId": "cleintid"
}