如何解决Spring Boot-从type []中找不到反向引用属性
我在春季有2个实体:具有OneToMany关系的类别和位置:
Category.java:
@Table(name = "category")
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
int id;
int parentId;
String name;
@OneToMany(mappedBy = "category")
@JsonManagedReference(value = "referenceCallInCategory")
List<Position> positionList;
// getters and setters
Position.java:
@Entity
public class Position {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
int id;
String position;
String company;
String description;
@ManyToOne
// @JsonBackReference (value = "referenceCallInPosition")
@JsonIgnoreProperties({"parentId","name","positionList"})
Category category;
// getters and setters
当我通过邮递员发出职位请求时,我在终端中收到以下警告:WARN 15904 --- [nio-8080-exec-2] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type,class positionsSite.positions.mode l.Position]]: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot handle managed/back reference 'referenceCallInCategory': no back reference property found from type [collection type; class java.util.List,contains [simple type,class positionsSite.positions.model.Position]]
奇怪的是,在对类别进行后请求时,会发生完全相同的警告,但是在对类别进行后请求后,职位的后请求可以正常工作。在我重新启动应用程序之前,它再次失败。
我拥有@JsonIgnoreProperties而不是@JsonBackReference的原因是,我在获取位置请求时需要Category.id。鉴于警告未找到反向引用属性,我尝试使用代码中注释的@JsonBackReference,但这并没有改变任何内容。
对于解决此问题的任何帮助将不胜感激
解决方法
如@darclander所述,this post清楚地说明了不同的@Json
属性。我的错误是我仍然有一个@JsonManagedReference
提出了问题。我删除了它,但并非一切都完美。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。