最近、休止状態 4 に移行しました。私たちのアプリケーションには、非推奨の session.connection () を持つ多くのファイルがあります。次のように呼び出して、 session.doWork() に置き換えました。
session.doWork(new Work() {
@Override
public void execute(Connection conn) throws SQLException {
wasAuto = conn.getAutoCommit();
if(!wasAuto) {
conn.rollback(); // in case there is existing transaction
conn.setAutoCommit(true);
}
}
});
try {
return mainCallback.doInHibernate(session);
} finally {
session.doWork(new Work() {
@Override
public void execute(Connection conn) throws SQLException {
if(!wasAuto)
conn.setAutoCommit(wasAuto);
}
});
}
しかし、私が言ったように、同じエラーを持つ多くのファイルがあります。上記のように書くのがベストプラクティスですか?
理解を深めるために、エラーのあるファイルを 1 つ追加します。誰かがエラーをクリアするのを手伝ってくれますか?
Session session = repo.getSessionFactory().openSession();
Connection connection = null;
PreparedStatement ps = null;
int recordCount = 0;
try {
connection = session.connection();
ps = connection.prepareStatement(masterSql);
ps.setDate(1,acctPeriod);
ps.setLong(2,geoScheme.getId());
recordCount = ps.executeUpdate();
long millis = System.currentTimeMillis() - start;
logger.info("END --> Generating/Running Dynamic SQL for Aggregation took "+(millis / 60000.0)+" min" );
run.addRollupMessage("Generating/Running Dynamic SQL for Aggregation took "+(millis / 60000.0)+" min" );
run.setEndDate(DateUtils.currentTimestamp());
logger.info("No of Loan groups inserted = " + recordCount);
run.addRollupMessage("No of Loan groups inserted = " + recordCount);
} catch (Exception err) {
throw new RuntimeException(" **ERROR** DURING AGGREGATION: " + err.getMessage(),err);
}
finally
{
if (ps != null) ps.close();
if (connection != null) connection.close();
if (session != null) session.close();
}