我是新來的休眠。我正在創建一些基本的hibernate程序來做一些插入MySql數據庫。以下是我寫的主要代碼。儘管我在事務處理完成後關閉會話,並在控制檯上看到「已發佈的JDBC連接」,但運行該程序後,我可以在數據庫中看到非活動連接。每次運行程序時,都會在數據庫中創建一個新的非活動連接。我必須在eclipse控制檯中單擊「終止」按鈕來停止每次不活動的會話。休眠不釋放mysql連接
Student s1 = new Student();
s1.setName("Monaj");
s1.setRoll(1);
s1.setDate(new Date());
Configuration configuration = new Configuration().configure();
serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
sessionFactory = configuration.configure()
.buildSessionFactory(serviceRegistry);
Session session=sessionFactory.openSession();
Transaction t1=session.beginTransaction();
session.save(s1);
t1.commit();
session.close();
控制檯輸出: -
15:29:08.476 [main] DEBUG o.h.e.j.i.LogicalConnectionImpl - Aggressively releasing JDBC connection
15:29:08.476 [main] DEBUG o.h.e.j.i.LogicalConnectionImpl - Releasing JDBC connection
15:29:08.476 [main] DEBUG o.h.e.j.i.LogicalConnectionImpl - Released JDBC connection
15:29:08.477 [main] DEBUG o.h.e.j.internal.JdbcCoordinatorImpl - HHH000420: Closing un-released batch
15:29:37.323 [pool-1-thread-1] DEBUG o.h.e.j.c.i.DriverManagerConnectionProviderImpl - Connection pool now considered primed; min-size will be maintained
Hibernate配置: -
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/test</property>
<property name="connection.password">password</property>
<property name="connection.username">admin</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<property name="connection.release_mode">AFTER_TRANSACTION</property>
<property name="connection.autocommit">true</property>
任何人都可以請幫我這。
你解決了這個問題嗎? –