1,hibernate db链接池:
java
若是打开log4j日志,运行hibernate过程,会有一段info日志:程序员
16:02:49,205 INFO DriverManagerConnectionProvider:64 - Using Hibernate built-in connection pool (not for production use!)
根据这段日志,官方文档亦有说明“嵌入的 Hibernate 链接池不用于产品环境。它缺少链接池里的几个功能。”,建议使用c3po/proxool第三方链接词,hibernate自建链接有超时问题等shell
2,查询部分:session
Person aPerson = (Person) session.createQuery("select p from Person p left join fetch p.events where p.id = :pid") .setParameter("pid", personId).uniqueResult(); // Eager fetch the collection so we can use it detached
a 经过:pid,进行设置参数,听说能够防止注入,还没有测试过,ide
b uniqueResult(),这个函数很好,看了下他的源码,函数
/** * Convenience method to return a single instance that matches * the query, or null if the query returns no results. * * @return the single result or <tt>null</tt> * @throws NonUniqueResultException if there is more than one matching result */ public Object uniqueResult() throws HibernateException;
正是在jdbc下比较繁琐的处理部分,这也就是hibernate封装到位的地方,让程序员专一于业务逻辑,忘记技术细节吧!测试
3,fetch