【发布时间】:2018-04-25 14:12:41
【问题描述】:
我在互联网上搜索了所有内容,但没有找到答案。
我有两个类之间的 oneToMany 关系,我想获得列表的一部分。
@Entity
@Table(name = "author")
class Author {
@Id
private Long id;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "AUTHOR_ID", referencedColumnName = "id")
private List<Book> books = new ArrayList<>();
}
@Entity
@Table(name="book")
class Book {
@Column
private Integer year;
@Column
private Integer position;
}
我想从特定作者那里获得特定年份且低于特定职位的所有书籍
@Query(From Book b where b.year=:year and b.position<:position and b.authorId=:id)
List<Book> getAllBooks(Integer year, Integer position, Long id)
我也试过了
@Query(From Book b where b.year=:year and b.position<:position and b.id in (select a.books.id from author a where a.id:=id)
谢谢你帮助我
【问题讨论】:
-
你能发布你的数据库结构吗
标签: java hibernate jpa hql jpql