原文地址:http://blog.csdn.net/v123411739/article/details/28644007 尊重原创,请访问原文地址
-
-
-
-
-
-
-
-
- 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();
-
-
-
-
-
-
-
-
- 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();
常用的Hql语句(转)
原文:http://www.cnblogs.com/zhaotiancheng/p/6527116.html