java - 如何使用关系表SpringBoot查找实体
问题描述
我正在尝试为 Delivery 制作 API。所以我有 Dish、Order 和 DishOrder 实体,我正在保存订单,但是当我尝试查找订单时,spring 给了我这个错误:
Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: could not extract ResultSet; nested exception is com.fasterxml.jackson.databind.JsonMappingException: could not extract ResultSet (through reference chain: java.util.ArrayList[0]->com.XYZ.model.entity.Order["orderDish"])]
我的代码或多或少是这样的:
命令:
@OneToMany(fetch = FetchType.LAZY)
private List<OrderDish> orderDishes;
盘子:
@OneToMany
@JsonIgnore
private List<OrderDish> orderDishes;
点菜:
@EmbeddedId
@JsonIgnore
private OrderDishId id;
OderDishId:
@JsonBackReference
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "id_dish", nullable = false, insertable = false, updatable = false)
private Dish dish;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "id_dish", nullable = false, insertable = false, updatable = false)
private Order order;
解决方案
推荐阅读
- ios - iOS - 通过本地推送通知触发通知服务扩展?
- typescript - Firebase 使用统计数据似乎被夸大了,我想了解为什么以下可观察到的结果会导致超过 70 次读取
- python - 从具有张量流概率的分布中采样时,张量是不可散列的错误(在 colab 上)
- javascript - 从角度的反应形式中获取预先填充的数据
- excel - 索引匹配excel多个条件
- continuous-integration - ZAP 的 GitLab CI 实现
- c# - 使用复合键 ASP.NET Web API 选择结果集(过滤器)
- r - R计划自动包更新
- python - matplotlib 表格中单元格内的文本
- python - 在我的文本文件 python 顶部创建的空行