title: How to set-up transactions for both web application and batch jobs using Spring and Hibernate
body: <p>I have an application which uses Spring 2.5 and Hibernate 3. </p>
  
  <p>There's a web application with a presentation layer, a servive layer and a DAO layer, as well as some Quartz jobs sharing the same service and DAO layers. </p>
  
  <p>Transactions are initialized in different layers with @Transactional annotations, like this:</p>
  
  <p><img src="https://i.stack.imgur.com/LkHHi.png" alt="alt text"></p>
  
  <p>It led me to a problem I described here: <a href="https://stackoverflow.com/questions/3843205/controlling-inner-transaction-settings-from-outer-transaction-with-spring-2-5">Controlling inner transaction settings from outer transaction with Spring 2.5</a></p>
  
  <p>I read a bit about how to set-up transactions to wire Spring and Hibernate together. It looks the recommended approach is to initialize transactions in the service layer. </p>
  
  <p>What I don't like is that most transactions exist only because they are required for hibernate to work properly.</p>
  
  <p>And when I really need a transaction for a job calling multiple service methods, it seems I don't have a choice to keep initializing transactions from the jobs. So moving @Transactional annotations from DAO to service doesn't seem to make any difference.</p>
  
  <p>How would you recommend to set-up transactions for this kind of application?</p>