aspose file tools*
The moose likes Struts and the fly likes Can't get the URL or File from the resource of hibernate.cfg.xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Reply locked New topic
Author

Can't get the URL or File from the resource of hibernate.cfg.xml file

Neeraj Khatana
Greenhorn

Joined: Jun 08, 2009
Posts: 7
Hi,

Below is the code given for HibernatePlugIn where the error is coming.

public class HibernatePlugIn implements PlugIn {

private String _configFilePath = "/WEB-INF/classes/hibernate.cfg.xml";

public static final String SESSION_FACTORY_KEY = SessionFactory.class.getName();

private SessionFactory _factory = null;

public void init(ActionServlet servlet, ModuleConfig config)
throws ServletException {
File file = new File(_configFilePath);

Configuration configuration = null;
URL configFileURL = null;
ServletContext context = servlet.getServletContext();

String file_configFilePath = context.getRealPath(_configFilePath);


try {

configFileURL = HibernatePlugIn.class.getResource(file_configFilePath);

configuration = (new Configuration()).configure(configFileURL); // java.lang.NullPointerException occurs in this line(Line no:69)
_factory = configuration.buildSessionFactory();

// Set the factory into session
context.setAttribute(SESSION_FACTORY_KEY, _factory);

} catch (HibernateException e) {
System.out.println("Error while initializing hibernate: "
+ e.getMessage());
e.printStackTrace(System.out);
}catch(Exception e) {
e.printStackTrace(System.out);
}
}

Below is the exception comes while starting the tomcat. I am using the Netbeans as IDE.
I tried it on tomcat 6.0 and tomcat 5.5. But in both the cases, I got the same error.
I am getting "configFileURL " parameter as null everytime.

java.lang.NullPointerException
at plugin.HibernatePlugIn.init(HibernatePlugIn.java:69)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:839)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:332)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4045)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4351)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)



I am fed up with this error. Everytime, I start the tomcat this error comes and my application does not start.

I don't get the URL or FILE object from the resource of hibernate.cfg.xml file. After that only, i proceed further to get the sessionfactory from this URL or FILE.

Please help me out in this situation.

Thanks and Regards
Neeraj
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please read this for more information.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Can't get the URL or File from the resource of hibernate.cfg.xml file