在调试我的服务器端代码时,我意识到我的删除行不起作用。我刚刚从我的插入中复制了这段代码,并将 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.flush 放在 session.delete 之后,但没有用。