hibernate分页实现
public List<Employee> pageQuery(int maxResult , int currentPage){ Session session = sf.openSession(); session.beginTransaction(); try { Query q = session.createQuery("from com.cx.hqlQuery.Employee"); q.setFirstResult((currentPage - 1)*maxResult); q.setMaxResults(maxResult); return q.list(); }catch (Exception e) { throw new RuntimeException(e); }finally { session.getTransaction().commit(); session.close(); } } @Test public void test(){ List<Employee> list = pageQuery(3,1); for (int i = 0 ; i < list.size() ; i++) { System.out.println(list.get(i).getEmpName()); } }
Hibernate对连接池(c3p0)的支持
作用管理链接;提升连接效率
在主配置文件里
<!--****************** 【连接池配置】****************** --> <!-- 配置连接驱动管理类 --> <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> <!-- 配置连接池参数信息 --> <property name="hibernate.c3p0.min_size">2</property> <property name="hibernate.c3p0.max_size">4</property> <property name="hibernate.c3p0.timeout">5000</property> <property name="hibernate.c3p0.max_statements">10</property> <property name="hibernate.c3p0.idle_test_period">30000</property> <property name="hibernate.c3p0.acquire_increment">2</property>