Hibernate PlugIn for Struts
I don't know that there's a need for a Hibernate PlugIn for Struts, but I wrote one today just for kicks. Pretty simple stuff that only requires you to have hibernate.cfg.xml in your WEB-INF/classes directory, and to add the following to your struts-config.xml.
<plug-in className="org.appfuse.webapp.util.HibernatePlugIn"/>
Then create the file org.appfuse.webapp.util.HibernatePlugIn
as follows:
public class HibernatePlugIn implements PlugIn { //~ Instance fields ======================================================== private Log log = LogFactory.getLog(HibernatePlugIn.class); //~ Methods ================================================================ public void init(ActionServlet servlet, ModuleConfig config) throws ServletException { try { SessionFactory sf = new Configuration().configure().buildSessionFactory(); if (log.isDebugEnabled()) { log.debug("Hibernate configuration completed."); } } catch (HibernateException h) { log.fatal("Error configuring Hibernate!", h); } } public void destroy() {} }
This doesn't seem to have any advantages over using a StartupListener, but it would be pretty sweet if it was included with Struts (or Hibernate), so you could simply put it in struts-config.xml and be done with it.
Posted by No one on May 31, 2003 at 07:04 PM MDT #
Posted by Matt Raible on May 31, 2003 at 07:14 PM MDT #