1

Investigation on a project of mine makes it appear that code triggered from a Spring @ModelAttribute is executed in a separate transaction (and separate Hibernate session) than the code executed by the @RequestMapping method. Is this by design? I fetch some small but not insignificant amount of data in model-attribute methods common to all my controllers (e.g. info on the current user) and the fact that it's all done in different sessions means that the database is often hit more than it should be.

Is it possible to configure this somehow or is this typical or intended behaviour?

Wouter Lievens
  • 4,019
  • 5
  • 41
  • 66
  • This has nothing to do with Spring. **You** define the transactions. Maybe implicitly. – a better oliver Nov 21 '14 at 20:41
  • @Wouter Lievens have a look at this [answer](http://stackoverflow.com/questions/25011568/spring-mvc-modelattribute-method) and this [blog](http://ankursinghal86.blogspot.in/2014/07/how-modelattribute-annotation-works-in.html). Also why don't you implement cache, then if data is common and not transactional it willalways hit the cache and not your DB. – Ankur Singhal Nov 22 '14 at 01:20

0 Answers0