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

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭