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(値=" a ")'、 '@JsonBackReference(値=" 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 
} 

は、同じ親クラスで2 @JSONBackRefrenceを使用して調達問題を解決しました。

関連する問題