我有2桌子。与… 1st有oneToMany关系2nd。
2
1st
oneToMany
2nd
类作者
@Entity @Table(name = "Author") Public class Author{ @Id @Column(name = "AuthorId") private int autherId; @Column(name = "AuthorName") private String authorName; @OneToMany @JoinColumn(name="AuthorId",referencedColumnName="AuthorId") List<Book> Books; //getter and setter }
课堂书
@Entity @Table(name = "Book") Public class Book{ @Id @Column(name = "BookId") private int bookId; @Column(name = "BookName") private String bookName; @Column(name = "AuthorId") private int authorId; //getter and setter }
如何编写Hql查询,以便能获得所有作者和那里的书,而且书名应以hello
Hql
hello
我知道使用这样的查询,
from Author;
我可以获取所有作者和那里的书,但是如何在书上注明条件?
我认为是这样的:
select a from Author as a join a.Book as ab where ab.AuthorId like '%"hello"%';
虽然不确定a.Book,也可能是a.Books,因为您的列名就是这样命名的。