0
我的代碼是解決冬眠nonuniqueobjectexception
@Transactional(propagation = Propagation.REQUIRED)
public void saveIndent(StockRequisitionCumIssue stockRequisitionCumIssue,
List<StockRequisitionCumIssueDetail> srciDetails,
List<StockRequisitionCumIssueDetail> removedObjects) {
sessionFactory.getCurrentSession().clear();
for (StockRequisitionCumIssueDetail srciDetail : removedObjects) {
objectLoader.delete(StockRequisitionCumIssueDetail.class, srciDetail);
}
objectLoader.save(StockRequisitionCumIssue.class, stockRequisitionCumIssue);
for (StockRequisitionCumIssueDetail srciDetail : srciDetails) {
srciDetail.setStockRequisitionCumIssue(stockRequisitionCumIssue);
objectLoader.save(StockRequisitionCumIssueDetail.class, srciDetail);
item.setOpeningQuantity(item.getOpeningQuantity().subtract(srciDetail.getQuantityIssued()));
item.setTotalValuation(item.getOpeningQuantity().multiply(item.getStandardCost()));
sessionFactory.getCurrentSession().update(item);
objectLoader.save(Item.class, item);
}
}
我試圖更新項目Object.But它沒有讓我更新同一twice.It拋出休眠nonuniqueobjectexception.Please幫助我,如果你有一個解決方案。
在此先感謝。
它看起來像你試圖堅持項目對象兩次。你能澄清objectLoader的作用嗎? – Julien
objectLoader.save只是爲了保存對象。它可以一次保存一個對象。只有當我試圖保存同一個項目兩次時纔會出現異常。 – Aranjit
我假設你的save()方法從會話對象中調用save()方法?這種方法試圖每次都堅持一個NEW實例(參見下面的答案) – Julien