.: Rollback transaction ใน hibernate :.
การ rollback transaction .ใน spring – hibernate
ใ ห้ประกาศ session มา session เดียวครับ แล้วจัดการภายใน session ทั้งหมด
Session session = getSession();
Transaction tx = null;
try {
// ส่วนของการทำงานทั้งหมด ที่ต้องการให้ rollback เวลาเกิด error
tx = session.beginTransaction();
session.createQuery("query")
.setString(":value", value).list();
id = (Long) session.save(Object);
session.flush();
tx.commit();
} catch(Exception e) {
logger.error("Can't create Object.", e);
tx.rollback();
} finally {
if(session != null) {
try {
session.close();
} catch(HibernateException e) {
e.printStackTrace();
}
}
}
ประยุกต์ดูนะครับ
February 16th, 2011 at 7:34 am
Decent statement on the subject of .: Rollback transaction ใน hibernate :. · @JDev – Blog brbr This is exactly why I often come back to the site and watching http://blog.abciloveu.com/rollback-transaction-%E0%B9%83%E0%B8%99-hibernate day after day.