我有两个表,多对多
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<>();
}
使用弹簧数据(JpaRepository)之类的findBySeanceIdAndRepertoireDayWeek()之类的休眠创建链接表repertoire_seance是否可以通过seancesId和repertoire.dayWeek获得机会?
答案 0 :(得分:0)
您可以通过编写HQL来实现。
它看起来像这样:
dataStamp