【发布时间】:2019-01-16 00:55:39
【问题描述】:
我的数据库中有两个表,author 和 book。以下是它们的结构:
书桌:
@Entity
public class Book {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String title;
@ManyToOne
private Author author;
...getters and setters...
}
作者表:
@Entity
public class Author {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
...getters and setters
}
我想通过书名获取特定书的作者。我已经在终端上使用了这个 sql 命令:select author.name as author from author right join book on author.id = book.author_id where book.title='Some title';。我应该如何在我的代码中构造查询来实现这一点?
【问题讨论】: