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
新闻热点
疑难解答