アプリケーションデータを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_connections
をpostgresql.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() + "|");
}
ロック情報:
私はないですHibernateのエキスパート、私はPostgresについていくつか知っています - Postgresはトランザクションの終了までロックしています。あなたのコードはトランザクションを終了しません。これはかなり重要な問題です。 –
t.commit();トランザクションを保存して終了します。 – Maverick
postgresを見てください - すべてのステートメントまたは待機ステートメントを記録してください - おそらく、休止状態はそれをしません。テーブルpg_stat_activityまたはlog_min_duration_statementオプションはあなたを助けることができます。 –