【发布时间】:2017-10-28 23:10:52
【问题描述】:
我也有类似的问题:Spring Data Jpa and Specification - how to work with ManyToOne and ManyToMany relations?
我有 3 个表:actor、movie 和 macors(电影和演员的连接表)和 spring boot,hibernate-jpamodelgen
@Entity
public class Actor {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
...
}
@Entity
public class Movie implements BaseId {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
....
}
我想要那些有 2 位或更多演员一起出演的电影。类似这样的查询:
select * from movie
join mactors on movie.id = mactors.movie
where mactors.actor = x and mactors.actor = y and ...;
public static Specification<Movie> findMoviesByActors(List<Long> actors) {
return (root, criteriaQuery, criteriaBuilder) -> {
...
return ...
};
}
我不知道接下来会发生什么。
任何提示将不胜感激。 谢谢
【问题讨论】:
标签: hibernate jpa spring-boot spring-data-jpa