我有两个实体
@Entity
public class Tabulka{
@OneToMany(mappedBy = "tabulka")
private List<VysledkyHraca> vysledkyHraca;
.
.
.
}
和
@Entity
public class VysledkyHraca{
@ManyToOne
private Tabulka tabulka;
.
.
.
}
这创建到表:tabulka与id和... 和VysledkyHraca的id ..和id_tabulka
如果我想要检索所有的tabulka ......好吧,这很简单:
@NamedQuery(name = Tabulka.Q_GET_ALL_TABULKY, query = "SELECT t FROM Tabulka t ")
但现在我想要检索所有tabulka然后再列出VysledkyHraca
我试试这个@NamedQuery(name = Tabulka.Q_GET_ALL_JOINTABULKY, query = "SELECT t FROM Tabulka t join t.vysledkyHraca")
,但它不起作用。请求帮助
答案 0 :(得分:2)
join需要别名
如果您只想获取它,请使用“join fetch”(不带别名)
答案 1 :(得分:0)
您仍在第二个查询中选择Tabulkas。尝试:
SELECT vh FROM Tabulka t join t.vysledkyHraca vh