Spring坿旗鷹盾裂?伊??Spring駁強Hibernate議糞?
扮寂:2011-03-29 javaeye jiwenke
O/R垢醤竃?岻朔?酒晒阻俯謹鹸墫議佚連隔消晒議蝕窟。Spring哘喘蝕窟宀辛參宥狛 Spring戻工議O/R圭宛厚圭宴議聞喘光嶽隔消晒垢醤?曳泌Hibernate?和中厘断祥 Spring+Hibernate嶄議Spring糞?恂匯倖酒汽議栃裂。
Spring斤Hinberanate議塘崔頁宥狛LocalSessionFactoryBean栖頼撹議?宸頁匯倖垢 皆Bean議糞??壓児窃AbstractSessionFactoryBean嶄?
Java旗鷹
/**
* 宸頁FactoryBean俶勣糞?議俊笥圭隈?岷俊函誼輝念議sessionFactory議 峙
*/
public Object getObject() {
return this.sessionFactory;
}
宸倖峙壓afterPropertySet嶄協吶?
Java旗鷹
public void afterPropertiesSet() throws Exception {
//宸倖buildSessionFactory頁宥狛塘崔佚連誼欺SessionFactory議仇圭
SessionFactory rawSf = buildSessionFactory();
//宸戦聞喘阻Proxy圭隈峨秘斤getCurrentSession議盛舜?誼欺才並暦?購 議session
this.sessionFactory = wrapSessionFactoryIfNecessary(rawSf);
}
厘断枠心心SessionFactory頁奕劔幹秀議?宸倖圭隈載海?淫根阻幹秀Hibernate議 SessionFactory議?勝化帶?
Java旗鷹
protected SessionFactory buildSessionFactory() throws Exception {
SessionFactory sf = null;
// Create Configuration instance.
Configuration config = newConfiguration();
//宸戦塘崔方象坿?並暦砿尖匂?LobHander欺Holder嶄?宸倖Holder頁匯倖 ThreadLocal延楚,宸劔宸乂彿坿祥才?殻鰯協阻
if (this.dataSource != null) {
// Make given DataSource available for SessionFactory configuration.
configTimeDataSourceHolder.set(this.dataSource);
}
if (this.jtaTransactionManager != null) {
// Make Spring-provided JTA TransactionManager available.
configTimeTransactionManagerHolder.set (this.jtaTransactionManager);
}
if (this.lobHandler != null) {
// Make given LobHandler available for SessionFactory configuration.
// Do early because because mapping resource might refer to custom types.
configTimeLobHandlerHolder.set(this.lobHandler);
}
//宸戦頁聞喘Hibernate議光倖奉來議塘崔?宸戦聞喘阻Configuration窃栖 渇?宸乂方象
try {
// Set connection release mode "on_close" as default.
// This was the case for Hibernate 3.0; Hibernate 3.1 changed
// it to "auto" (i.e. "after_statement" or "after_transaction").
// However, for Spring''s resource management (in particular for
// HibernateTransactionManager), "on_close" is the better default.
config.setProperty(Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.ON_CLOSE.toString());
if (!isExposeTransactionAwareSessionFactory()) {
// Not exposing a SessionFactory proxy with transaction- aware
// getCurrentSession() method -> set Hibernate 3.1 CurrentSessionContext
// implementation instead, providing the
|