为什么Hibernate数据库连接没有释放?
我在hibernate.cfg.xml中加入<property name="hibernate.connection.release_mode">after_transaction</property>,如下所示
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:test</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">scott</property>
<property name="hibernate.connection.password">tiger</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="connection.pool_size">8</property>
<property name="hibernate.connection.release_mode">after_transaction</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<mapping resource="events/Event.hbm.xml"/>
</session-factory>
</hibernate-configuration>
然后在程序中执行如下操作:
Session session = HibernateUtil.getSessionFactory().getCurrentSessio();
session.beginTransaction();
Event theEvent = new Event();
theEvent.setTitle(title);
theEvent.setDate(theDate);
session.save(theEvent);
session.getTransaction().commit();
Thread.sleep(120000);
在程序执行Thread.sleep(120000)语句时,数据库连接应该已经释放,但是却发现数据库连接处于inactive状态,数据库连接根本没有释放,为什么会这样?如何修改?