Announcement Announcement Module
No announcement yet.
Migrating from OpenSessionInViewInterceptor to TransactionManager Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Migrating from OpenSessionInViewInterceptor to TransactionManager

    I have an old Spring-based application that has been upgraded over the years to Spring 2.5.6 (it also uses Hibernate 3). I have a bunch of old DAO classes that extend HibernateDaoSupport. Now I'm trying to figure out how to get new controllers to handle sessions properly so that lazy loading works as expected.

    In the past, with Spring MVC I just used sionInViewInterceptor to make sure I always had a session available to support lazy loading. The interceptor is bound to my controllers by way of the interceptor configuration in a SimpleUrlHandlerMapping.

    Now I'm adding some new features and I'm using the more modern approach with the @Controller and @RequestMapping annotations and whatnot.

    In a new application, I just set up a TransactionManager bean and then used @Transactional on my DAO classes to make sure that the proper session is used.

    I'm trying to figure out the best approach in terms of migrating my old DAOs to work with my new controllers. Should I figure out how to bind my old OpenSessionInViewInterceptor to the new controllers configured using @RequestMapping or map those new controllers using my old SimpleUrlHandlerMapping? Or should I tweak the DAOs to use the TransactionManager? Or is there a better alternate approach?

    My old stuff works fine the old way and my new stuff works fine the new way, but I'm having trouble figuring out the best approach to getting the old DAOs to work with the new controllers.

  • #2
    Using the OpenSessionInViewFilter which saves you from adding the Interceptor. Or simply declare your OpenSessionInViewInterceptor on the DefaultAnnotationHandlerMapping.. It really doesn't matter if it is a Controller or a @Controller.