サーバー側のコードをデバッグしているときに、削除行が機能していないことに気付きました。このコードを挿入からコピーし、session.saveORUpdateをsession.deleteに置き換えました。オブジェクトを削除する正しい方法ですか?私はここで何が間違っているのですか?
例外はありません。
public void delete(Object dataStore) throws DidNotSaveRequestSomeRandomError {
Transaction txD;
Session session;
session = currentSession();
//get first and then fallback to begin.
if (session.getTransaction() != null
&& session.getTransaction().isActive()) {
txD = session.getTransaction();
} else {
txD = session.beginTransaction();
}
try {
session.delete(dataStore);
} catch (MappingException e) {
e.printStackTrace() ;
}
try {
txD.commit();
while (!txD.wasCommitted())
;
} catch (ConstraintViolationException e) {
log.error("Unable to delete data from "
+ dataStore.getClass().toString());
txD.rollback();
throw new DidNotSaveRequestSomeRandomError(dataStore,
feedbackManager);
} catch (TransactionException e) {
log.debug("txD state isActive" + txD.isActive()
+ " txD is participating" + txD.isParticipating());
log.debug(e);
txD.rollback();
} finally {
session.flush();
txD = null;
session.close();
}
}
編集 :
session.deleteの後にsession.flushを入れてみましたが、機能しませんでした。