views:

38

answers:

2

I knew ORM tools, such as Hibernate, have their own transaction management mechanism. We can also harness transaction by using JDBC directly. And DBMS has its transaction facilities either. I wonder that in which layer(s) the transaction is actually implemented in a J2EE application? I guess that the transaction in Hibernate is built upon on JDBC, in turn the JDBC rely the underlying DBMS to realize the Transaction. is it fair?

Regards!

+3  A: 

In the service layer, of course.

In EJB, they're on session beans.

In Spring, they're on services.

Services know about units of work. That's why they own the transaction context.

duffymo
A: 

Transaction service is not implemented at any particular application layer. If you mean by where you are going to use transaction service, it depends on your requirement. Sometimes transaction demarcation can be at view layer itself, see OpenSessionInView

Adi
This doesn't work so well if you change or add view technologies (e.g., embellish your web tier with a mobile UI). The mobile UI will want to call services via HTTP, so the transactions should remain on the service.
duffymo
read 'sometimes' and how many web applications you see have mobile interfaces? Even in those scenarios I expect you will face similar problem with hibernate proxies described in the link I provided .
Adi