首页 > 解决方案 > 如何使用关系表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;

标签: javaspring-bootapirestspring-data-jpa

解决方案


推荐阅读