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()}