首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

spring、hibernate源码分析2

2012-10-08 
spring、hibernate源码分析二从上篇文章分析得出,hibernate初始化时,flushBeforeCompletion、autoCloseSessi

spring、hibernate源码分析二

从上篇文章分析得出,hibernate初始化时,flushBeforeCompletion、autoCloseSession默认为false

releaseMode为auto。还有hibernate.jdbc.batch_size默认为0等。那现在来分析openSession和getCurrentSession的区别就不难了。

? ? 首先进入sessionFactory的实现类SessionFactoryImpl,接到上篇文章继续分析:

上篇文章的configuration最后调用代码如下:

?

?

?默认会采用jta事物

那么现在调用openSession继续追踪

?

?

?进入ThreadLocalSessionContext继续追踪

?

继续跟踪this.jdbcContext = new JDBCContext( this, connection, interceptor );session和collection的关联过程

?

private void openConnection() throws HibernateException {if ( connection != null ) {return;}log.debug("opening JDBC connection");try {connection = factory.getConnectionProvider().getConnection();}catch (SQLException sqle) {throw JDBCExceptionHelper.convert(factory.getSQLExceptionConverter(),sqle,"Cannot open connection");}callback.connectionOpened(); // register synch; stats.connect()}

热点排行