- explicitly by the application
- explicitly by the application with ThreadLocal pattern (example)
- via Hibernate transaction demarcation with JTA
- via Hibernate transaction demarcation with plain JDBC
- using Spring Framework
- using EJB / CMT (container-managed transactions)
Basic Approach: Managed by Application
Here's a code sample from hibernate document:
Session session = factory.openSession(); Transaction tx = null; try { tx = session.beginTransaction(); // Do some work session.load(...); session.persist(...); tx.commit(); // Flush happens automatically } catch (RuntimeException e) { tx.rollback(); throw e; // or display error message } finally { session.close(); }You choose the approach.
No comments:
Post a Comment