У меня есть следующее определение в родительском объекте CommentTarget:
// bi-directional many-to-one association to EmployerDetails
@OneToMany(mappedBy = "commentTarget", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Comment> comments;
, и это определено в дочернем комментарии:
@ManyToOne(cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH} )
@JoinColumn(name = "comment_target_id")
private CommentTarget commentTarget;
Однако, когда я беру список из цели и возвращаемое как JSON:
@RestController
@RequestMapping("/ticketV2")
public class TicketV2Controller {
@Autowired
CommentTargetService commentTargetService;
@RequestMapping(value = "/{ticketId}/comments", method = RequestMethod.GET)
public List<Comment> getTicketComments(@PathVariable(value="ticketId") String id,
@RequestParam String type){
CommentTarget commentTarget = commentTargetService.findByTargetIdAndTargetType(Long.valueOf(id), TargetName.valueOf(type));
List<Comment> commentsList = commentTarget.getComments();
return commentsList;
}
Оно выкидывается, сохраняя ссылку на цель, затем список в ней и так далее:
[
{
"id": 997,
"commentedBy": 1,
"commenterName": "Exchange Admin",
"comment": "123456",
"commentTarget": {
"id": 703,
"targetId": 216,
"targetName": "TICKET",
"created": 1586548428358,
"updated": 1586548428358,
"comments": [
{
"id": 997,
"commentedBy": 1,
"commenterName": "Exchange Admin",
"comment": "123456",
"commentTarget": {
"id": 703,
"targetId": 216,
"targetName": "TICKET",
"created": 1586548428358,
"updated": 1586548428358,
"comments": [
{
"id": 997,
"commentedBy": 1,
"commenterName": "Exchange Admin",
"comment": "123456",
"commentTarget": {
"id": 703,
"targetId": 216,
"targetName": "TICKET",
"created": 1586548428358,
"updated": 1586548428358,
"comments": [
{
"id": 997,
"commentedBy": 1,
"commenterName": "Exchange Admin",
"comment": "123456",
"commentTarget": {
"id": 703,
"targetId": 216,
"targetName": "TICKET",
"created": 1586548428358,
"updated": 1586548428358,
"comments": [
Не уверен как разделить отношения между ними, когда просто нужно вернуть дочерний список комментариев.