日期:2014-05-16 浏览次数:20436 次
JPQL主要用于JPA查询数据,和SQL语句的语法大同小异;
最基本的查询:
SELECT p
FROM Player p
查询出所有的player,包括其子类,也可以写成这样
From Player as p
去除重复的元素
SELECT DISTINCT
?p
FROM Player p
WHERE p.position = ?1
关键字DISTINCT去除了重复的元素,并且接受参数设置条件过滤
结合查询关联
SELECT DISTINCT p
FROM Player p, IN(p.teams) t
查询所有有team的player
也可以写成如下:
SELECT DISTINCT p
FROM Player p JOIN p.teams t
或者:
SELECT DISTINCT p
FROM Player p
WHERE p.team IS NOT EMPTY
关联关系的查询过滤
SELECT t