2017-02-14 6 views
0

アプリケーションデータをOracleからPostgreSQLに移行しています。PostgreSQLがテーブルからロックを解除しない

環境詳細:
のJava 1.8
のPostgreSQL 9.5のEnterprise Edition(XAデータソース)
にHibernate 4.3
WildFly 9.0.2

我々は、最新のPostgreSQLのドライバを(使用しているのpostgresql-1212年4月9日。 jdbc42.jar)https://jdbc.postgresql.org/download.html

編集:edb-jdbc17.jaも試してみました。 rドライバはpostgresエンタープライズdbに付属しています。それと同じ結果。

またmax_prepared_connectionspostgresql.confファイルに設定しました。

以下のメソッドは、オブジェクトを取得し、hibernate開始トランザクションを使用してトランザクションをコミットしています。メソッドはエラーまたは例外をスローしません。しかし、データベースでは、オブジェクトは保存されず、アプリケーションはデッドロックの原因となっているテーブルのロックを取得しています。 同じコードはOracleと完全に機能します。

データベースから
public void createObject(Object obj) throws CSTransactionException { 
    Session s = null; 
    Transaction t = null; 
    try { 

     try { 
      obj = performEncrytionDecryption(obj, true); 
     } catch (EncryptionException e) { 
      throw new CSObjectNotFoundException(e); 
     } 


     try{ 
      obj = ObjectUpdater.trimObjectsStringFieldValues(obj); 
     }catch(Exception e){ 
      throw new CSObjectNotFoundException(e); 
     } 



     s = HibernateSessionFactoryHelper.getAuditSession(sf); 
     t = s.beginTransaction(); 
     s.save(obj); 
     t.commit(); 
     s.flush(); 
     auditLog.info("Creating the " + obj.getClass().getName().substring(obj.getClass().getName().lastIndexOf(".")+1) + " Object ");   
    } 
catch (PropertyValueException pve) 
    { 
     try { 
      t.rollback(); 
     } catch (Exception ex3) { 
      if (log.isDebugEnabled()) 
       log.debug("Authorization|||createObject|Failure|Error in Rolling Back Transaction|" + ex3.getMessage()); 
     } 
     if (log.isDebugEnabled()) 
      log 
        .debug("Authorization|||createObject|Failure|Error in Rolling Back Transaction|" + pve.getMessage()); 
     throw new CSTransactionException(
       "An error occured in creating the " + StringUtilities.getClassName(obj.getClass().getName()) + ".\n" + " A null value was passed for a required attribute " + pve.getMessage().substring(pve.getMessage().indexOf(":")), pve); 
    } 
    catch (ConstraintViolationException cve) 
    { 
     try { 
      t.rollback(); 
     } catch (Exception ex3) { 
      if (log.isDebugEnabled()) 
       log.debug("Authorization|||createObject|Failure|Error in Rolling Back Transaction|" + ex3.getMessage()); 
     } 
     if (log.isDebugEnabled()) 
      log 
        .debug("Authorization|||createObject|Failure|Error in Rolling Back Transaction|" + cve.getMessage()); 
     throw new CSTransactionException(
       "An error occured in creating the " + StringUtilities.getClassName(obj.getClass().getName()) + ".\n" + " Duplicate entry was found in the database for the entered data" , cve); 
    }  
    catch (Exception ex) { 
     log.error(ex); 
     try { 
      t.rollback(); 
     } catch (Exception ex3) { 
      if (log.isDebugEnabled()) 
       log 
         .debug("Authorization|||createObject|Failure|Error in Rolling Back Transaction|" 
           + ex3.getMessage()); 
     } 
     if (log.isDebugEnabled()) 
      log 
        .debug("Authorization|||createObject|Failure|Error in creating the " 
          + obj.getClass().getName() 
          + "|" 
          + ex.getMessage()); 
     throw new CSTransactionException(
       "An error occured in creating the " 
         + StringUtilities.getClassName(obj.getClass() 
           .getName()) + "\n" + ex.getMessage(), ex); 
    } finally { 
     try { 

      s.close(); 
     } catch (Exception ex2) { 
      if (log.isDebugEnabled()) 
       log 
         .debug("Authorization|||createObject|Failure|Error in Closing Session |" 
           + ex2.getMessage()); 
     } 
    } 
    if (log.isDebugEnabled()) 
     log 
       .debug("Authorization|||createObject|Success|Successful in creating the " 
         + obj.getClass().getName() + "|"); 
} 

ロック情報:

+0

私はないですHibernateのエキスパート、私はPostgresについていくつか知っています - Postgresはトランザクションの終了までロックしています。あなたのコードはトランザクションを終了しません。これはかなり重要な問題です。 –

+0

t.commit();トランザクションを保存して終了します。 – Maverick

+0

postgresを見てください - すべてのステートメントまたは待機ステートメントを記録してください - おそらく、休止状態はそれをしません。テーブルpg_stat_activityまたはlog_min_duration_statementオプションはあなたを助けることができます。 –

答えて

0

あなたは(finallyブロックで理想的に)コミット後にセッションをクローズする必要があります。

s = HibernateSessionFactoryHelper.getAuditSession(sf); 
t = s.beginTransaction(); 
    try { 
      s.save(obj); 
      session.flush(); 
      session.clear(); 
      t.commit(); 
      auditLog.info("Creating the " + obj.getClass().getName().substring(obj.getClass().getName().lastIndexOf(".")+1) + " Object ");   
     }   
    }catch (Exception e) { 
     t.rollBack(); 
    }finally{ 
     s.close(); 
    } 
+0

返事Maciejありがとう。私は最終的にブロックでセッションを終了しています。私は完全なメソッド定義を貼り付けました。 – Maverick

+0

@Leozeo Maciejの例で宣言されている 't.commit()'の前に 'session.flush()'を作成してみてください – rvit34

+0

トランザクションコミット前にセッションをフラッシュしようとしましたが動作しませんでした。 – Maverick

関連する問題