データベースに存在しないエンティティを削除しようとしていますが、delete()メソッドで例外が発生しません。
存在しないエンティティを削除しようとすると、どうすればエラーが発生しますか?
以下にコードをコピーしました。
public void remove(MyEntity persistentInstance) {
logger.debug("removing entity: " + persistentInstance);
try {
sessionFactory.getCurrentSession().delete(persistentInstance);
logger.debug("remove successful");
} catch (final RuntimeException re) {
logger.error("remove failed", re);
throw re;
}
}
編集:
次のコードを使用して、テストでremoveを呼び出します。
final MyEntity instance2 = new MyEntity (Utilities.maxid + 1); //non existent id
try {
mydao.remove(instance2);
sessionFactory.getCurrentSession().flush();
fail(removeFailed);
} catch (final RuntimeException ex) {
}
フラッシュと呼んでもテストは失敗しません、なぜですか?
例外を取得したいのですが。とにかく、delete()がいつ例外をスローできるかを理解することにも興味があります。