-
hibernate中常用的Hql语句总结
-
- hql = "FROM Employee";
- hql = "FROM Employee AS e";
- hql = "FROM Employee e";
-
- hql = "FROM Employee WHERE id<10";
- hql = "FROM Employee e WHERE e.id<10";
- hql = "FROM Employee e WHERE e.id<10 AND e.id>5";
-
- hql = "FROM Employee e WHERE e.id<10 ORDER BY e.name";
- hql = "FROM Employee e WHERE e.id<10 ORDER BY e.name DESC";
- hql = "FROM Employee e WHERE e.id<10 ORDER BY e.name DESC, id ASC";
-
- hql = "SELECT e FROM Employee e";
- hql = "SELECT e.name FROM Employee e";
- hql = "SELECT e.id,e.name FROM Employee e";
- hql = "SELECT new Employee(e.id,e.name) FROM Employee e";
-
- Query query = session.createQuery("FROM Employee e WHERE id<3");
- query.setFirstResult(0);
- query.setMaxResults(10);
-
- List list = session.createQuery(
- "FROM Employee e")
- .setFirstResult(0)
- .setMaxResults(10)
- .list();
-
- hql = "SELECT COUNT(*) FROM Employee";
- hql = "SELECT min(id) FROM Employee";
-
- hql = "SELECT e.name,COUNT(e.id) FROM Employee e GROUP BY e.name";
- hql = "SELECT e.name,COUNT(e.id) FROM Employee e GROUP BY e.name HAVING count(e.id)>1";
- hql = "SELECT e.name,COUNT(e.id) FROM Employee e WHERE id<9 GROUP BY e.name HAVING count(e.id)>1";
- hql = "SELECT e.name,COUNT(e.id) " +
- "FROM Employee e " +
- "WHERE id<9 " +
- "GROUP BY e.name " +
- "HAVING count(e.id)>1 " +
- "ORDER BY count(e.id) ASC";
- hql = "SELECT e.name,COUNT(e.id) AS c " +
- "FROM Employee e " +
- "WHERE id<9 " +
- "GROUP BY e.name " +
- "HAVING count(e.id)>1 " +
- "ORDER BY c ASC";
-
-
- hql = "SELECT e.id,e.name,d.name FROM Employee e JOIN e.department d";
- hql = "SELECT e.id,e.name,d.name FROM Employee e INNER JOIN e.department d";
-
- hql = "SELECT e.id,e.name,d.name FROM Employee e LEFT OUTER JOIN e.department d";
-
- hql = "SELECT e.id,e.name,d.name FROM Employee e RIGHT JOIN e.department d";
-
- hql = "SELECT e.id,e.name,e.department.name FROM Employee e";
-
- hql = "FROM Employee e WHERE id BETWEEN ? AND ?";
- List list2 = session.createQuery(hql)
- .setParameter(0, 5)
- .setParameter(1, 15)
- .list();
-
- hql = "FROM Employee e WHERE id BETWEEN :idMin AND :idMax";
- List list3 = session.createQuery(hql)
- .setParameter("idMax", 15)
- .setParameter("idMin", 5)
- .list();
-
- hql = "FROM Employee e WHERE id IN (:ids)";
- List list4 = session.createQuery(hql)
- .setParameterList("ids", new Object[] { 1, 2, 3, 5, 8, 100 })
- .list();
-
- int result = session.createQuery(
- "UPDATE Employee e SET e.name=? WHERE id>15")
- .setParameter(0, "无名氏")
- .executeUpdate();
- int result1 = session.createQuery(
- "DELETE FROM Employee e WHERE id>15")
- .executeUpdate();
-
相关阅读:
C# 插件构架实战(Jack H Hansen )
.Net 中的反射(动态创建类型实例) Part.4
css3新添加属性>calc()
详解IIS Express的详细配置、使用和注意事项
SpringBoot 整合 Shiro 实现登录拦截
java MD5 加密
MyBatis xml foreach循环语句
java 考试系统 在线学习 视频直播 人脸识别 springboot框架 前后分离 PC和手机端
Spring Boot 事物回滚
allowedOrigins cannot contain the special value "*" gateway 报错
-
原文地址:https://www.cnblogs.com/zhangshitong/p/5227420.html
Copyright © 2020-2023
润新知