I have two entities, Movie and Genre, with a many to many relationship from genre to movie. Genre being the “parent” of the relationship.
This generates three tables: genre
, movie
and genre_movie
@Entity
public class Genre {
@Id
@GeneratedValue(strategy = AUTO)
private Long id;
@ManyToMany(fetch = LAZY)
@JoinTable( name = "genre_movie",
joinColumns = {@JoinColumn(name = "genre_id")},
inverseJoinColumns = {@JoinColumn(name = "movie_id")}
)
private Set<Movie> movies = new HashSet<>();
...
}
@Entity
public class Movie {
@Id
@GeneratedValue(strategy = AUTO)
private Long id;
...
}
I it possible perform this query using the criteria query api? Filter movies based on their genre id.
select *
from movie
join genre_movie on movie.id = genre_movie.movie_id
where genre_id = 19;