Hibernate Version: 2.1.4
Database: SQL Server
Use of multiple datasources
Use of Spring Framework
Hi there,
I've spent the good portion of the day reading through posts on the Hibernate forum regarding different strategies for handling lazy loading in the context of a web application architecture. We've been using Hibernate for about 3 months now and our architecture is based on Struts with our Struts actions talking to DAOs which then front Hibernate. After reading the article titled "Session and Transaction Scope" (
http://www.hibernate.org/168.html) it appears that are model is based on the session-per-operation antipattern where our application hits the DAO multiple times during a web request and each fetch method in the DAO opens and closes the session. I see that the documentation in the "Session and Transaction Scope" article says this is a bad approach but it doesn't say why. Is there too much overhead in opening and closing a session multiple times within a request?
Second, which approach is best given our architecture of Struts -> DAOs -> Hibernate? I also read the article titled "Thread Local Session" (
http://www.hibernate.org/42.html) in which an approach to maintaing a Hibernate session is detailed. What I'm fuzzy about is whether or not we want to use the Spring framework to implement the Hibernate session maintenance and whether or not the Spring framework will handle multiple session factories. Currently, we have the Spring framework configured to handle multiple session factories for each of the 5 databases with which we need to communicate.
Lastly, will the Thread Local Session approach solve the lazy loading problems we are seeing in our application by keeping the session open? I realize there are several solutions for solving lazying loading, including the servlet filter fronting all requests and reattaching the parent object to a new session. With respect to the latter approach, where would I perform the reattachment of the parent object given an architecture of Struts Actions -> DAOs -> Hibernate? I know there has to be a few other people reattaching objects to new sessions inside an architecture that supports DAOs so I'm curious what everyone else is doing. This post alludes to at least one:
http://forum.hibernate.org/viewtopic.ph ... t=reattach
Thanks for your time.
Ricardo