haha thanks. i used to use the HibernateTemplate back before i understood anything. now that i look back, i was using a framework to simplify another framework. thats exactly what anti-java people refer to when they mention framework bloat and complexity.
Quote:
The back end is responsible for managing the persistence code, but it should be responsible for the transaction demarcation. Let that be done at a higher level, indeed.
i think u meant to write "should NOT BE responsible", right?
the problem with the whole idea of where to properly demarcate transactions (and in hibernate's case, Sessions) is the following:
1. it is always said that a DAO should hide all persistence logic. if people see Hibernate code like session.beginTransaction(), the first reaction is, ok its hibernate related so it has to be hidden behind a DAO interface. this is wrong and leads to the session-per-operation anti-pattern
2. back before AOP and the whole contextual session management from Hibernate 3, it was very unclear as to how one should demarcate a transaction without binding your service level to a transaction API (and in this case Hibernate). so immediately people dont (or at least i didnt for a long time) fully understand how one encapsulates persistence related code from higher layers in an application
3. in web containers there was always the Open Session in View pattern but this wasnt/isnt applicable for stand alone applications that arent modeled around the "session-per-request" pattern. in my eyes, its still not clear for people that are new to java and this whole domain as to how one should demarcate a transaction in a stand alone application without the help of AOP or some direct invocation of the "start/stop/rollback" methods from within service layer objects.
i wish i could draw a picture on here. i think it would clarify a lot of stuff for people new to this stuff