I just started using WebWork2 yesterday, and I'm sold. A new techonology hasn't kept me smiling for so long thinking "this is right" since I first started playing with Ruby.I have declared the Thread Local Session (say PersistenceManager) as a component in xwork (application scope), all my dao implement PersistenceManagerAware and i have a servlet filter which make sure that at the end of the request the hibernate session is closed like this :
I'm writing a vanilla database backed webapp for my client, and I'm trying to decide where I should put the persistence code within the WW2 framework. Right now I've implemented the Thread Local Session seen here ( http://hibernate.bluemars.net/42.html ). I created a DAO which uses the Thread Local Session to retrieve and persist the business objects. I've made the DAOs components on the session and any actions that need them are enabled for the DAOs.
The thing is this seems clunky to me. I've only been using the framework for two days, but something about this approach doesn't feel like I'm fully leveraging WW's capabilities. I can't quite get my nose on the smell, but it's definitely there.
Any ideas? I'm sure this is a problem that's been solved many times over.
Anoop
------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Opensymphony-webwork mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork
HibernateFilter ------------------------------------------------------------------------------------------------ public class HibernateFilter implements Filter, PersistenceManagerAware { private Log log = LogFactory.getLog(this.getClass()); private ComponentManager componentManager; private PersistenceManager persistenceManager;
public void setPersitenceManager(PersistenceManager persistenceManager) { this.persistenceManager = persistenceManager; }
public void init(FilterConfig filterConfig) throws ServletException
{
ComponentManager componentManager = (ComponentManager) filterConfig.getServletContext().getAttribute("DefaultComponentManager");
componentManager.initializeObject(this);
}
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException
{
filterChain.doFilter(servletRequest, servletResponse);
try
{
persistenceManager.closeSession();
}
catch (HibernateException e)
{
log.error(e.getMessage(), e);
}
}
public void destroy() {
} } -------------------------------------------------------------------------------------------------
This way your views will still be able to fetch objects on the fly.
Regards Christian Meunier
------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Opensymphony-webwork mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork