81,092
社区成员
发帖
与我相关
我的任务
分享
HTTP Status 500 - Could not write JSON: failed to lazily initialize a collection of role: com.wfy.web.model.MobileInbound.mobiles, could not initialize proxy - no Session; nested exception is com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role: com.wfy.web.model.MobileInbound.mobiles, could not initialize proxy - no Session (through reference chain: com.wfy.web.common.ServerResponse["data"]->java.util.ArrayList[0]->com.wfy.web.model.MobileInbound["mobiles"])
出错的实体类部分代码
@Entity
@Table(name = "t_mobile_inbound")
@JsonIgnoreProperties(ignoreUnknown = true, value = {"hibernateLazyInitializer","handler","fieldHandler"})
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@DynamicUpdate
public class MobileInbound {
private String id;
private Supplier supplier;
private MobileModel mobileModel;
private Color color;
private Config config;
private double buyPrice;
private int quantity;
private double amount;
private Date inputTime;
private User inputUser;
private Date checkTime;
private User checkUser;
private CheckStatus status;
private Dept dept;
private String remark;
private List<MobileStock> mobiles;
@OneToMany(mappedBy = "mobileInbound", cascade = CascadeType.ALL)
public List<MobileStock> getMobiles() { // 这个字段一对多对应另一个实体,就是懒加载报错的地方
return mobiles;
}
public void setMobiles(List<MobileStock> mobiles) {
this.mobiles = mobiles;
}
//省略其余getters, setters