baliukas wrote:
It must be simple to understand: Session and DB transaction lifespan is the same.
FYI, that's exactly how Hibernate Session management is implemented in the Spring Framework: A Spring-managed, Hibernate-aware transaction demarcates both a database transaction and the lifespan of the associated Hibernate Session.
Spring also clearly separates transaction demarcation and transaction participation: This addresses units-of-work that span multiple DAO method invocations. Under the hood, a ThreadLocal Session is used, but application code does not have to bother.
Effectively, Spring offers all the benefits of EJB CMT or BMT, i.e. declarative or programmatic transaction demarcation, for lightweight POJOs. In addition, it offers pluggable transaction strategies: JTA is just one option; demarcating code does not depend on any particular strategy.
Spring's Hibernate transaction strategy is perfect for accessing a single database with Hibernate. This enables declarative, high-level transaction management for Hibernate without any JTA or EJB dependency - for example, in plain Tomcat or a standalone application!
Juergen