hibernate_文档笔记

1,hibernate db连接池:

   如果打开log4j日志,运行hibernate过程,会有一段info日志:

16:02:49,205  INFO DriverManagerConnectionProvider:64 - Using Hibernate built-in connection pool (not for production use!)

   根据这段日志,官方文档亦有说明“嵌入的 Hibernate 连接池不用于产品环境。它缺乏连接池里的几个功能。”,建议使用c3po/proxool第三方连接词,hibernate自建连接有超时问题等


2,查询部分:

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,进行设置参数,据说可以防止注入,尚未测试过,

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,





你可能感兴趣的:(hibernate_文档笔记)