Spring @ModelAttribute methods executed in same session/transaction as @RequestMapping

318 views Asked by At

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?

0

There are 0 answers