首页 文章

Hibernate没有发布mysql连接

提问于
浏览
3

我是hibernate的新手 . 我正在创建一些基本的hibernate程序来做一些插入MySql数据库 . 以下是我写的主要代码 . 虽然我在事务之后关闭会话并在控制台上看到“已发布的JDBC连接”,但在运行程序后,我可以在数据库中看到非活动连接 . 每次运行程序时,都会在数据库中创建一个新的非活动连接 . 我必须在eclipse控制台中单击“终止”按钮,以便每次都停止该非活动会话 .

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

休眠配置: -

<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>

有谁可以帮我这个 .

================================添加分析================ ===========

对于Server,有一个解决此问题的方法,例如在使用IBM WebSphere时,有一个最小连接池选项 . 如果我们做到0.我认为它会得到解决 .

但对于使用eclipse的独立应用程序,不确定是什么问题 . :(

1 回答

  • 0

    尝试将连接释放模式设置为“自动”

    <property name="connection.release_mode">auto</property>
    

    有关详细信息,请参阅manual .

    希望这可以帮助..

相关问题