我有两张桌子有关多对多

public class Repertoire {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false, unique = true)
    private Integer id;

    private String name;
    private Integer dayWeek;

    @ManyToMany(cascade = CascadeType.REMOVE)
    @JoinTable(
            name = "repertoire_seance",
            joinColumns = { @JoinColumn(name = "repertoire_id")},
            inverseJoinColumns = {@JoinColumn(name = "seance_id")}
    )
    List<Seance> seances = new ArrayList<>();
}




    public class Seance {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false, unique = true)
    private Integer id;

    private java.time.LocalTime displayTime;

    @ManyToOne
    private Film film;

    @Column(length=127)
    private String kind;


    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
    private Hall hall;

    @OneToMany(mappedBy = "reservationSeance")
    @JsonIgnore
    private List<Reservation> reservations = new ArrayList<>();
}


休眠创建链接表repertoire_seance可以通过使用春天数据(JpaRepository)之类的findBySeanceIdAndRepertoireDayWeek()来通过seancesId和repertoire.dayWeek通过seancesId和repertoire.dayWeek获得机会吗?

最佳答案

您可以通过编写HQL来实现。

它看起来像这样:

select s from Repertoire r inner join r.seances s where r.dayWeek ="Your Value" and s.id = "Your Id Value"

关于java - 从两个表中获取多对多的记录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52067074/

10-09 00:33