many-to-many-spring-jpa不返回json中的所有数据

aor9mmx1  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(174)

我创造了一种多对多的关系。它正在正确返回数据。但是,我注意到,如果数据存在于json的canuse部分,并且之前被另一个播放器调用过,那么它不会再次打印数据,只会打印新的值。
约森

[
    {
        "id": 12,
        "firstname": "asdfghjkl ",
        "surname": "asda",
        "canUse": [
            {
                "id": 0,
                "techniqueName": "JAVA"
            },
            {
                "id": 1,
                "techniqueName": "PHP"
            },
            {
                "id": 2,
                "techniqueName": "PYTHON"
            }
        ]
    },
    {
        "id": 49,
        "firstname": "asc",
        "surname": "as",
        "canUse": []
    },
    {
        "id": 90,
        "firstname": "LOL",
        "surname": "LOL",
        "canUse": []
    }*,
    {
        "id": 91,
        "firstname": "Kareem",
        "surname": "LOL",
        "canUse": [
            1,
            2,
            {
                "id": 3,
                "techniqueName": "HASKELL"
            }
        ]
    },*
    {
        "id": 92,
        "firstname": "Omar",
        "surname": "LOL",
        "canUse": []
    }
]

玩家实体

@Entity
@Table(name = "players")
@EntityListeners(AuditingEntityListener.class)
@JsonIdentityInfo(
        generator = ObjectIdGenerators.PropertyGenerator.class,
        property = "id")
public class Players {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="player_id")
    private int id;
    private String firstname;
    private String surname;
    @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinTable(
            name = "able_to_use",
            joinColumns = {@JoinColumn(name = "player_id", referencedColumnName = "player_id")},
            inverseJoinColumns = {@JoinColumn(name = "technique_id", referencedColumnName = "id")}
    )
    private List<Technique> canUse;
    //Getters and Setters

技术实体

@Entity
@Table(name = "technique")
@EntityListeners(AuditingEntityListener.class)

@JsonIdentityInfo(
        generator = ObjectIdGenerators.PropertyGenerator.class,
        property = "id")
public class Technique {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    @Column(name = "technique_name")
    private String techniqueName;
    @JsonIgnore
    @ManyToMany(mappedBy = "canUse", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private List<Players> ableToUse;
      //Getters and Setters

提前谢谢,问题发生在id为91的玩家身上。这个播放器也应该打印php和python,但是只打印id。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题