我是JPQL的新手,我有3个实体类Book,Loan,member,relationship 贷款图书(@OneToOne)单向 贷会员(@OneToMany)单向
我贷款类的片段
public class loan implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
private String dateofissue;
private String dueDate;
@OneToOne
@JoinColumn(name = "bookid")
private book Bookid;
@ManyToOne
@JoinColumn(name="member_ID")
private member memberid;
当我写一个非常简单的查询"从贷款贷款中选择贷款&#34 ;;由于关系
,我得到所有列,包括列成员和书籍如何编写JPQL查询以返回选定列book.title,book.id,loan.duedate,member.firstname,member.id from book,loan,member
查询的目的是通过所有成员
来检索所有借来的书籍谢谢
答案 0 :(得分:0)
您已经定义了映射,因此只需在JPQL中直接引用它们。
select l.Bookid.title, l.Bookid.id, loan.duedate, l.memberid.firstname,
l.memberid.id from loan l;
或者您也可以为较短的名称创建别名。
select book.title, book.id, loan.duedate, member.firstname, member.id
from loan l join l.Book book join l.Member member;