我有以下型号
GameModel
// ...
@ManyToMany(cascade = CascadeType.DETACH)
@JoinTable(
name = "game_genre",
joinColumns = { @JoinColumn(name = "game_id") },
inverseJoinColumns = { @JoinColumn(name = "genre_id") } )
private List<GenreModel> genres;
// ...
GenreModel
// ...
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "name", nullable = false, unique = true, length = 50)
private String name;
@ManyToMany(mappedBy = "genres")
private List<GameModel> games;
// ...
我也有他们的资料库。
如何获得ID为 1 的所有属于(例如) 类型的游戏?在 GameModel 中,我没有任何类型的列,因此我无法使用findByGenresContaining在 GameRepository 中做到这一点。
答案 0 :(得分:0)
感谢@billalGHILAS 它是这样的:
// find games that belong to one genre
public List<GameModel> findByGenresId(int id);
// find games that belong to list of genres
public List<GameModel> findByGenresIdIn(List<Integer> id);