2017-04-04 1 views
1

클래스에 여러 개의 역 참조 클래스가 있습니다. 나는 그들에게 @JsonBackReference을 사용하기 때문에 오류가 발생합니다. 해당 클래스에 @JsonIdentityInfo 주석을 할당했지만 여전히 동일한 오류가 발생합니다.이름이 'defaultReference'인 다중 역 참조 속성

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'

어떻게하면이 오류를 해결할 수 있습니까? 한 클래스에서 여러 개의 역 참조를 사용할 수 없습니까?

답변

1
Jackson's javadoc에 따르면

, 모두 @JsonManagedReference@JsonBackReference은 그들을 함께 결합하는 이름 값 동의 : 나는 또한이 문제에 직면

@JsonBackReference("a") 
    private A a; 

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

각 관계에 대한 이름 값을 추가했습니다. 나는 여전히 같은 오류가 발생합니다. – Eniss

+0

'defaultReference'와 (과) 동일한 오류가 발생 했습니까? 얼마나 이상한가 –

+0

예, 나는 또한 @JsonManagedReference (value = "a")','@JsonBackReference (value = "a")와 같은 오류를 시도했는데 여전히 동일한 오류 – Eniss

0

을하지만, 마지막에 나는 그것을 해결. 부모 클래스 문제 해결

@JsonIgnoreProperties("inspection")@JsonManagedReference을 언급함으로써

//This is parent class 
@Entity 
@Table(name = "checklist") 
@JsonIgnoreProperties("inspection") 
public class Checklist implements java.io.Serializable { 

    @ManyToOne 
    @JoinColumn(name = "product_id", referencedColumnName = "id") 
    @JsonBackReference 
    private Product product; 

    @OneToMany(mappedBy = "checklists", cascade = CascadeType.ALL) 
    @JsonManagedReference 
    private Set<Inspection> inspection = new HashSet<Inspection>(); 
//Constructor 
//Getter and Setter 
} 

//This is child class 
@Entity 
@Table(name = "inspections") 
public class Inspection { 

    @ManyToOne 
    @JoinColumn(name = "chk_id", referencedColumnName = "id") 
    private Checklist checklists; 
//Constructor 
//Getter and Setter 
} 

는 같은 부모 클래스에서 두 @JSONBackRefrence를 사용하여 올렸다.