我在春天有一个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
它停在这里每个人,有人可以提出一些建议吗?我不知道
答案 0 :(得分:0)
您必须在执行操作后关闭事务和会话。如果当前会话和事务未打开,则您为新操作打开了新事务。这将导致您的数据库挂起。
答案 1 :(得分: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;
}