gpt4 book ai didi

java - Spring boot : java. lang.IllegalStateException:提交响应后无法调用 sendError()

转载 作者:行者123 更新时间:2023-12-01 18:32:24 24 4
gpt4 key购买 nike

由于@OneToOne,我收到此错误。提交响应后无法调用 sendError() 有人可以帮我弄清楚如何解决它吗?

这是我的模型:

@Entity
@SequenceGenerator(name = "RECOMMENDATION_SQ", sequenceName = "recommendation_sequence")
public class Review {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "RECOMMENDATION_SQ")
private Long id;

@ManyToOne
private Restaurant restaurant;

@ManyToOne
private User user;

private Date date;

@Lob
private byte[] image;

private String text;

@OneToOne(fetch=FetchType.LAZY, cascade = {CascadeType.ALL})
@JoinColumn(name="id_rating")
private Rating rating;

--

@Entity
@SequenceGenerator(name = "RATING_SQ", sequenceName = "rating_sequence")
public class Rating {

@Id
@GeneratedValue
private Long id_rating;

@OneToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "rating")
@JsonIgnore
private Review review;

private int dish;
private int service;
private int price;
private int location;
private int accessibility;

我尝试添加@JsonIgnore(此解决方案:Spring Boot : Error :Cannot call sendError() after the response has been committed),但出现此错误:

InvalidDefinitionException: No serializer found for class 
org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor and no properties discovered to create
BeanSerializer

我还尝试删除获取类型,但它也不起作用。

最佳答案

因此,对我有用的解决方案是我在其中一个模型中使用 @MapsId 并从另一个类中删除该字段。使用@MapsId,您不需要双向关联。欲了解更多详细信息,您可以阅读这篇文章:https://vladmihalcea.com/the-best-way-to-map-a-onetoone-relationship-with-jpa-and-hibernate/

@Entity
@SequenceGenerator(name = "RECOMMENDATION_SQ", sequenceName =
"recommendation_sequence")
public class Review {

@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "RECOMMENDATION_SQ")
private Long id;

@ManyToOne
private Restaurant restaurant;

@ManyToOne
private User user;

private Date date;

@Lob
private byte[] image;

private String text;

@OneToOne(fetch = FetchType.LAZY)
@MapsId
@JoinColumn(name = "id")
private Rating rating;

--

@Entity
@SequenceGenerator(name = "RATING_SQ", sequenceName = "rating_sequence")
public class Rating {

@Id
@GeneratedValue
private Long id;

private int dish;
private int service;
private int price;
private int location;
private int accessibility;

关于java - Spring boot : java. lang.IllegalStateException:提交响应后无法调用 sendError(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60136152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com