I am using RAD 6.0 . Doing an application using struts and hibernate
I am using hibernate3.jar from hibernate-distribution-3.3.2.GA-dist.zip(i am newbie to hibernate)
In my Hibernate plugin class , I tried creating a configuration object but the application exits when below red coloured statement in init(ActionServlet servlet, ModuleConfig modConfig) is encountered
package com.tutorial.hibernate;
import java.net.URL; import javax.servlet.ServletException;
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts.action.ActionServlet; import org.apache.struts.action.PlugIn; import org.apache.struts.config.ModuleConfig; import org.hibernate.cfg.*; import org.hibernate.cfg.Configuration; import org.hibernate.*;
public class HibernatePlugin implements PlugIn { private Configuration config; private SessionFactory factory; private String path = "/hibernate.cfg.xml"; private static Class hpclass = HibernatePlugin.class; public static final String KEY_NAME = hpclass.getName(); private static Log log = LogFactory.getLog(hpclass);
public void setPath(String path) { this.path = path; }
public void init(ActionServlet servlet, ModuleConfig modConfig) throws ServletException { try { URL url = HibernatePlugin.class.getResource(path); config=new Configuration(); config.configure(url); factory = config.buildSessionFactory(); servlet.getServletContext().setAttribute(KEY_NAME, factory); } catch (MappingException e) { log.error("Mapping errors:", e); String messages = e.getMessage(); //for (int i = 0; i < messages.length; i++) log.error(messages, e); throw new ServletException(); } catch (HibernateException e) { log.error("Hibernate errors:", e); String errors = e.getMessage(); //for (int i = 0; i < errors.length; i++) log.error(errors, e);
throw new ServletException(); } catch (Exception e) { log.error("Hibernate errors:", e); String errors = e.getMessage(); //for (int i = 0; i < errors.length; i++) log.error(errors, e);
throw new ServletException(); } }
public void destroy() { try { factory.close(); } catch (HibernateException e) { log.error("Unable to close factory", e); } }
}
Kindly help me out it is urgent for me to finish this and move on ..
|