Hibernate的hql常用语句整理汇总
//普通查询
hql = "from User";
//条件查询 where
hql = "from User where UserName='张三’";
模糊查询 like
hql = "from User where UserName like '%羽%'";
// 逻辑条件查询 >
hql = "from User c where c.createDate >'2011-08-08'";
// 逻辑条件查询 between and
hql = "from User c where c.createDate between '2013-04-19' and '2046-04-19'";
逻辑多条件查询and
hql = "from User c where c.createDate between '2013-04-19' and '2046-04-19' and c.UserName like '%世%'";
// update 更新
hql = "update User as c set c.createDate='2011-03-03' where c.UserType.UserTypeId=3";
// delete删除
hql = "delete from User as c where c.createDate='2011-03-04'";
// 多个属性查询 面向对象方式
hql = "select new User(c.UserName,c.createDate) from User as c";
// 函数查询
hql = "select count(*),max(c.createDate) from User as c";
// 排序
hql = "from User as c order by c.createDate desc";
// 分组
hql = "from User as c group by c.UserType.UserTypeId";
// inner join 查询结果为多个对象的集合
hql = "from User as c inner join c.UserType";
// leftJoin 查询结果为多个对象的集合
hql = "from UserType as c left join c.Users";
// rightJoin 查询结果为多个对象的集合
hql = "from UserType as c right join c.Users";
// 使用子查询
hql = "from UserType as c where (select count(*) from c.Users)>0";