首页 > 学院 > 开发设计 > 正文

Hibernate的检索方式(下)

2019-11-06 08:22:03
字体:
来源:转载
供稿:网友

1.连接查询

      1.1迫切左外连接 HQL方式
session.createQuery("from aaa a left join fetch a.b b where xxx")QBC方式
session.createCriteria(aaa.class).setFetchMode("b",FetchMode.JOIN).add(Restrictiona.eq())1.2左外连接HQL方式:检索策略是映射文件的策略
session.createQuery("from aaa a left join a.b b where xxx")1.3内连接HQL方式
session.createQuery("from aaa a inner join  a.b b where xxx")1.4迫切内连接HQL方式:会忽略映射文件的策略
session.createQuery("from aaa a innerjoin fetch a.b b where xxx")HQL方式:

2.投影查询

     子查询部分实体或者实体的部分属性。用select来实现。
session.createQuery("select c.name from aaa c where xxx")session.createQuery("select  new A(c.name) from aaa c where xxx")//把aaa表查询数来的name作为参数传给A,返回A对象。

3.报表查询

    3.1使用聚集函数count(),max(),min(),sun() .avg()
session.createQuery("select count(*) from aaa a").uniqueResult()3.2分组查询 使用group by having 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表