java – 无法处理托管/后向引用’defaultReference’:找不到后引用属性

我有两个模型类.一个是

@Entity(name = "userTools")
@Table(uniqueConstraints = @UniqueConstraint(columnNames = { "assignToUser_id","toolsType_id" }))
@Inheritance(strategy = InheritanceType.JOINED)
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS,include = JsonTypeInfo.As.PROPERTY,property = "className")
@JsonIgnoreProperties(ignoreUnknown = true)
public class UserTools {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @OneToOne
    private ToolsType toolsType;

    @OneToMany(mappedBy = "userTools",fetch = FetchType.EAGER,cascade = { CascadeType.ALL },orphanRemoval = true)
    @Cascade(org.hibernate.annotations.CascadeType.DELETE)
    @JsonManagedReference
    private List

第二是

@Entity(name = "userToolsHistory")
@JsonIgnoreProperties(ignoreUnknown = true)
public class UserToolsHistory {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @OneToOne
    private ToolsType toolsType;

    @ManyToOne
    @JsonIgnore
    @JsonBackReference
    private UserTools userTools; 

    private String comments;
}

但是在保存时我收到了这个错误:

Can not handle managed/back reference 'defaultReference': no back
reference property found from type [collection type; class
java.util.List,contains [simple type,class
com.dw.model.tools.UserToolsHistory]]
最佳答案
您面临的例外源于MappingJackson2HttpMessageConverter.

要修复它,请交换注释,以便获得:

public class UserTools {
...
@JsonBackReference
private List

本教程解释了必须如何完成:jackson-bidirectional-relationships-and-infinite-recursion

相关文章

这篇文章主要介绍了spring的事务传播属性REQUIRED_NESTED的原...
今天小编给大家分享的是一文解析spring中事务的传播机制,相...
这篇文章主要介绍了SpringCloudAlibaba和SpringCloud有什么区...
本篇文章和大家了解一下SpringCloud整合XXL-Job的几个步骤。...
本篇文章和大家了解一下Spring延迟初始化会遇到什么问题。有...
这篇文章主要介绍了怎么使用Spring提供的不同缓存注解实现缓...