首页 > 代码库 > Hibernate Hql 总结(2)---laoyang
Hibernate Hql 总结(2)---laoyang
package com.etc.test; import java.util.Iterator; import java.util.List; import org.hibernate.Query; import org.hibernate.Session; import org.junit.Test; import com.etc.dao.HibernateSessionFactory; import com.etc.entity.Dept; import com.etc.entity.Emp; public class testd { //@Test public void findAll() { Session s = HibernateSessionFactory.getSession(); Query q = s.createQuery(" from Emp emp where emp.ename like ‘%S%‘"); List<Emp> list = q.list(); for(Emp e:list) { System.out.println(e); } } //@Test public void findByEname() { Session s = HibernateSessionFactory.getSession(); Query q = s.createQuery(" from Emp where ename like ‘%S%‘"); q.setMaxResults(3); q.setFirstResult(0); List<Emp> list = q.list(); for(Emp e:list) { System.out.println(e); } } //@Test public void group() { Session s = HibernateSessionFactory.getSession(); Query q = s.createQuery("select emp.dept,count(emp.empno) from Emp emp group by emp.dept "); Iterator it = q.iterate(); while(it.hasNext()) { Object o[] = (Object[]) it.next(); Dept d = (Dept)o[0]; System.out.println(d.getDname()+"员工个数为:"+o[1]); } } @Test public void findBySal() { Session s = HibernateSessionFactory.getSession(); Query q = s.createQuery("from Emp emp where emp.sal>2000 and dept.deptno = 20"); List<Emp> list = q.list(); System.out.println(list); } }
Hibernate Hql 总结(2)---laoyang
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。