下面的代碼默默無法更新數據庫。這裏沒有錯誤消息要報告。看起來好像行「sessionFactory.getCurrentSession()。saveOrUpdate(sn);」 (朝着片段的底部)被忽略。我究竟做錯了什麼?Hibernate SessionFactory未保存更改
public String getSerialNumber(String id) {
log.debug("--------------------------------------------------------------------------------------------Looking for Serial number counter named: " + id);
SerialNumber sn = (SerialNumber) sessionFactory.getCurrentSession().get(SerialNumber.class, id);
if (sn == null) {
//TODO Throw an error (maybe). The code below creates a new Serial number counter
log.debug("NO Serial Number for: " + id + " was found.");
sn = new SerialNumber();
sn.setSerialNumberId(id);
sn.setName("Unspecified");
sn.setValue(1);
log.debug("-----------------------------------------" + sn.toString());
sessionFactory.getCurrentSession().save(sn);
log.debug("--------------------------------------------------------------------------------------------Right after SAVE call. This is id --> " + id);
return "1";
}
sn.setValue(sn.getValue()+1);
log.debug("--update---------------------------------" + sn.toString());
log.debug("--update---------------------------------" + sn.getValue());
sessionFactory.getCurrentSession().saveOrUpdate(sn);
log.debug("--update---------------------------------" + sn.getValue());
log.debug("--update------------------------------------------------------------------------------------Right after SAVE call. This is id --> " + id);
return sn.getValue().toString();
}
你犯任何地方? – jeff 2012-07-25 14:39:21
將代碼包裝在try catch中,查看是否有任何異常被拋出。 – david99world 2012-07-25 14:41:14
沒有發現錯誤。 – user1269651 2012-07-25 14:43:04