gpt4 book ai didi

java - 名称为 'defaultReference' 的多个反向引用属性

转载 作者:行者123 更新时间:2023-11-30 06:48:50 24 4
gpt4 key购买 nike

我在一个类中有多个反向引用类。由于我为它们使用 @JsonBackReference ,因此出现错误。我为这些类分配了 @JsonIdentityInfo 注释,但仍然遇到相同的错误。

public class X implements Serializable {
....
//bi-directional many-to-one association to Booking
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "xxA", nullable = false)
@JsonBackReference
private A a;

//bi-directional many-to-one association to Client
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "xxB", nullable = false)
@JsonBackReference
private B b;
...getters setters
}

@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
public class B implements Serializable {
........
//bi-directional many-to-one association to BookedClient
@OneToMany(mappedBy = "b", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JsonManagedReference
private List < X > xxB;
........ getters setters
}


@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
public class A implements Serializable {
........
//bi-directional many-to-one association to BookedClient
@OneToMany(mappedBy = "a", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JsonManagedReference
private List < X > xxA;
........ getters setters
}

错误:

com.fasterxml.jackson.databind.JsonMappingException: Multiple back-reference properties with name 'defaultReference'

如何解决此错误?我不能在类中使用多个反向引用吗?

最佳答案

根据Jackson's javadoc@JsonManagedReference@JsonBackReference 都接受将它们绑定(bind)在一起的名称值:

  @JsonBackReference("a")
private A a;

@JsonManagedReference("a")
private List < X > xxA;

关于java - 名称为 'defaultReference' 的多个反向引用属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43202883/

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