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