-
Query接口: 1.org.hibernate.Query接口,定义有执行查询的方法,该方法完成HQL语句的解析和执行过程,并返回查询结果; 2.Query接口支持方法链编程风格,使得程序代码更为简洁 3.Query实例的创建:1)Session的createQuery()方法创建Query实例;2)createQuery方法包含一个HQL语句参数,createQuery(hql) 4.Query执行查询:1)Query接口的list()方法执行HQL查询;2)list()方法返回结果数据类型为java.util.List,List集合中存放符合查询条件的持久化对象。查看全部
-
HQL查询语言需要注意的问题: 1.HQL是面向对象的查询语言,对Java类与属性大小写敏感 2.与SQL形式相似,本质不同 3.HQL对关键字不区分大小写(为了美观及可读性,习惯小写)查看全部
-
HQL语句形式,基本和SQL语句形式一致,但是如图所示,HQL语句中from子句是不可或缺的,而其他子句都可以省略。查看全部
-
HQL定义: 1.Hibernate Query Language,Hibernate查询语言 2.HQL是面向对象的查询语言(Hibernate框架会将HQL语言解析成SQL然后执行数据库的查询) 3.HQL提供了丰富灵活的查询特性,Hibernate官方推荐查询方式查看全部
-
HQL查询子句 检索对象——from子句(指定要查询的持久化对象) 选择——select子句(选择查询持久化对象中的指定属性 ) 限制——where子句(限制持久化对象的查询范围) 排序——order by子句(对查询结果进行排序)查看全部
-
hibernate中的集合运算查看全部
-
默认懒加载状态,默认不查询外键信息对应的数据查看全部
-
String hql = "from Commodity order by price asc"; // 升序 String hql = "from Commodity order by price desc"; // 降序 String hql = "from Commodity order by seller.id asc ,price desc, name asc";查看全部
-
查询单个对象 uniqueResult String hql = "from Customer as c where c.id=1"; Query query = session.createQuery(hql); Customer c = (Customer)query.uniqueResult(); System.out.println(c);查看全部
-
集合运算 String hql = "from Order where o.orderItems is not empty ";查看全部
-
模糊查询匹配 String hql = "from Customer as c where c.name like '张_'"; String hql = "from Customer as c where c.address like '%北京%'";查看全部
-
范围查询 String hql = "from Customer as c where c.age in(20,40)"; String hql = "from Customer as c where c.age not in(20,40)"; String hql = "from Customer as c where c.age between 20 and 40"; String hql = "from Customer as c where c.age not between 20 and 40";查看全部
-
null值判断 String hql = "from Commodity as c where c.description != null"; String hql = "from Commodity as c where c.description <> null"; String hql = "from Commodity as c where c.description = null";查看全部
-
使用distinct取出重复的元素 String hql = "select distinct c.sex from Customer as c"; Query query = session.createQuery(hql); List<Object> objs = query.list(); for (Object obj : objs) { System.out.println(obj); }查看全部
-
以map形式返回 String hql = "select new map(s.id as id,s.name as name,s.tel as tel) from Seller as s"; Query query = session.createQuery(hql); List<Map> maps = query.list(); for (Map map : maps) { System.out.println(map.get("id")+" "+map.get("name")+" "+map.get("tel")); }查看全部
举报
0/150
提交
取消