2

我在春天有一个 api,它在 postgres db 上执行 crud 操作。几次插入后,它试图打开一个新的 jdbc 连接并永远挂起。

[DEBUG,StatefulPersistenceContext,main] initializing non-lazy collections
[TRACE,JDBCContext,main] after autocommit
[DEBUG,ConnectionManager,main] transaction completed on session with on_close connection      release mode; be sure to close the session to release JDBC resources!
[TRACE,SessionImpl,main] after transaction completion
[INFO,Initializer,main] Creating publisher user for lisa penny
[DEBUG,DefaultListableBeanFactory,main] Returning cached instance of singleton bean 'transactionManager'
[DEBUG,HibernateTransactionManager,main] Creating new transaction with name     [org.temp.demo.core.dao.hb.GenericHibernateDAO.makePersistent]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
[DEBUG,SessionImpl,main] opened session at timestamp: 13657283326
[DEBUG,HibernateTransactionManager,main] Opened new Session     
[org.hibernate.impl.SessionImpl@3a1ca1a4] for Hibernate transaction
[DEBUG,HibernateTransactionManager,main] Preparing JDBC Connection of Hibernate Session   [org.hibernate.impl.SessionImpl@3a1ca1a4]
[DEBUG,JDBCTransaction,main] begin
[DEBUG,ConnectionManager,main] opening JDBC connection

它停在这里,任何人都可以提出一些建议吗?我没有任何线索

4

2 回答 2

0

关闭事务和会话示例。找到你的自动装配类并作为我的例子进行更改。

public ContentResult insertNewContent( Content content )
    {
        ContentResult result = this.validateContent( content );

        if( result.hasErrors() == false )
        {
            Session session = this._hibernateSessionFactory.openSession();
            Transaction tx = null;

            try
            {
                //important !
                tx = session.beginTransaction();

                session.save( content );

                tx.commit();

                if( content.get_id() > 0 )
                {

                }
                else
                {
                    result.addError( ContentResult.CODES.ERROR_INVALID_ID );
                }

            }
            catch( HibernateException e )
            {
                //important !
                if( tx != null )
                {
                    tx.rollback();
                }
                ContentRepository.logger.error( "insertNewContent failed" );        
                e.printStackTrace();
            }
            finally
            {
                //important !
                session.close();
            }
        }

        return result;

    }
于 2014-08-15T06:23:51.833 回答
0

操作后必须关闭事务和会话。如果不是当前会话和事务正在打开,并且您为新操作打开了新事务。这将导致您的数据库挂起。

于 2014-08-15T04:43:31.410 回答