2013-04-12 3 views
2

나는 봄에 api를 가지고있어서 postgres db에 대한 crud 연산을 수행한다. 몇 가지 삽입 후 새 JDBC 연결을 열려고 시도하고 영원히 멈 춥니 다.spring postgres와의 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  
[[email protected]] for Hibernate transaction 
[DEBUG,HibernateTransactionManager,main] Preparing JDBC Connection of Hibernate Session [or[email protected]] 
[DEBUG,JDBCTransaction,main] begin 
[DEBUG,ConnectionManager,main] opening JDBC connection 

여기에 모두 중지됩니다. 아무에게도 제안 할 수 있습니까? 실마리가 없습니다

+0

웹 응용 프로그램입니까? 응용 프로그램을 다시 시작하면 어떻게됩니까? (나는 그것을 다시 실행하고 몇 가지 삽입이 다시 끊어 질 것이라고 가정합니다) DBMS에 열려있는 연결을 확인하는 도구가 있습니까? – Rafa

+0

네, 그게 정확히 무슨 일이야, 내가 다시 시작하면 몇 삽입 후 중단. 그것은 웹 응용 프로그램입니다. 스레딩 문제 나 이전 트랜잭션이 제대로 닫히지 않습니다. 하지만 처음 몇 번 제대로 작동하는지 확인하십시오. 나는 pgAdmin3을 가지고 있는데, 어떤 도구가 필요한가요? –

+0

걸려있는 거래를 아십니까? 특정 작업을 수행하려고 할 때만 매달려서 문제의 원인을 파악하면 문제를 해결하는 데 도움이 될 수 있습니다. 같은 시도 : http://heatware.net/databases/how-active-sql-queries-open-connections-postgres/를 – Rafa

답변

0

작업을 수행 한 후에 트랜잭션과 세션을 닫아야합니다. 현재 세션과 트랜잭션이 열리지 않았다면 새 작업을 위해 새 트랜잭션을 열었습니다. 그러면 데이터베이스가 중단됩니다.

0

트랜잭션 및 세션 예제를 닫습니다. autowired 클래스를 찾고 내 예제로 변경하십시오.

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; 

    }