hibernate 工作的實現原理步驟

step1:創建Configuration:進行配置文件的裝載操作,提取所有配置文件進行解析。

step2:創建SessionFactory對象:託尼各國創建好的Configurtation對象可以創建一個sessionFactory對象的實例,他是產生Session對象實例的工廠,它在整個應用中應該是唯一的。

step2:創建Session對象:Session對象類似於數據庫的連接對象,可以理解爲於數據庫建立的一個連接,但他的功能比JDBC重的Connection的對象豐富很多。

step4開始一個事物  在Java中定義一個事物操作的開始,這是使用Hibernate進行持久化操作必不可少的步驟。

step5 進行持久化操作,在這個步驟中可以讀取或者保存java對象。

step6 結束事物 顯示的結束事物

step 7關不Session ,類似於釋放數據庫的連接。

 

示例:STEP1:6:34:23,890 DEBUG TransactionInterceptor:363 - Getting transaction for [com.hongwei.athena.service.OrganizationService.findUpperOrgsByUserId]

STEP2:16:34:23,890 DEBUG TransactionSynchronizationManager:139 - Retrieved value [org.springframework.orm.hibernate3.SessionHolder@1d78908] for key [org.hibernate.impl.SessionFactoryImpl@18e2044] bound to thread [http-8080-8]

STEP3:16:34:23,921 DEBUG AbstractBatcher:410

 

6:34:23,953 DEBUG TransactionInterceptor:392

16:34:23,968 DEBUG JDBCTransaction:134 - commit
16:34:23,984 DEBUG JDBCTransaction:227 - re-enabling autocommit

 

 

16:34:26,562 DEBUG JDBCTransaction:147 - committed JDBC Connection
16:34:26,562 DEBUG ConnectionManager:325 - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
16:34:26,562 DEBUG HibernateTransactionManager:964 - Triggering afterCommit synchronization
16:34:26,562 DEBUG HibernateTransactionManager:980 - Triggering afterCompletion synchronization
16:34:26,562 DEBUG TransactionSynchronizationManager:311 - Clearing transaction synchronization
16:34:26,562 DEBUG DataSourceUtils:202 - Resetting read-only flag of JDBC Connection [10383317(com.mysql.jdbc.JDBC4Connection@166fec0)]
16:34:26,562 DEBUG HibernateTransactionManager:741 - Not closing pre-bound Hibernate Session [org.hibernate.impl.SessionImpl@1304435] after transaction
16:34:26,562 DEBUG SessionImpl:401 - disconnecting session
16:34:26,562 DEBUG ConnectionManager:464 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
16:34:26,578 DEBUG ConnectionManager:325 - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
16:34:26,578 DEBUG DefaultActionInvocation:57 - No result returned for action com.hongwei.athena.web.action.reminder.ReminderAction at null
16:34:26,578 DEBUG I18nInterceptor:57 - after Locale=zh
16:34:26,578 DEBUG I18nInterceptor:57 - intercept }
16:34:26,578 DEBUG ActionContextCleanUp:57 - skipping cleanup counter=1
16:34:26,578 DEBUG TransactionSynchronizationManager:229 - Removed value [org.springframework.orm.hibernate3.SessionHolder@9dc7a4] for key [org.hibernate.impl.SessionFactoryImpl@18e2044] from thread [http-8080-1]
16:34:26,578 DEBUG OpenSessionInViewFilter:207 - Closing single Hibernate Session in OpenSessionInViewFilter
16:34:26,578 DEBUG SessionFactoryUtils:784 - Closing Hibernate Session

發佈了29 篇原創文章 · 獲贊 1 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章