File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Problem with Hibernate sessionFactoryBean in application context initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Problem with Hibernate sessionFactoryBean in application context initialization" Watch "Problem with Hibernate sessionFactoryBean in application context initialization" New topic
Author

Problem with Hibernate sessionFactoryBean in application context initialization

Hernan Amaya
Greenhorn

Joined: Jul 01, 2010
Posts: 7
I get the following exception


SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/ro-data.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1412)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:546)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
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:583)
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:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.NullPointerException
at org.hibernate.mapping.ManyToOne.createPropertyRefConstraints(ManyToOne.java:70)
at org.hibernate.cfg.HbmBinder$ManyToOneSecondPass.doSecondPass(HbmBinder.java:2733)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1163)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1469)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409)
... 27 more





Here is ro-data.xml

Peter Mularien
Author
Ranch Hand

Joined: Sep 06, 2007
Posts: 84
From the error:

It looks like you have a problem with one of the many-to-one mappings you have specified in your Hibernate configuration (one of the Hibernate XML mapping files). You'll have to enable logging or set a breakpoint in a debugger to figure out which one it is. Hope that helps!

Author, Spring Security 3 (the Book), Packt Publishing, 2010
SCJP, OCP
Hernan Amaya
Greenhorn

Joined: Jul 01, 2010
Posts: 7
It was that indeed! I checked every many-to-one mapping and I found the error. Nevertheless, I have found other errors. How do I do to set a breakpoint to have a better understanding of each error, or how do I enable logging? Thank you.
Peter Mularien
Author
Ranch Hand

Joined: Sep 06, 2007
Posts: 84
Well, setting up a breakpoint depends on your IDE - simply run your app in debug mode (or use the JVM's remote debugging features to attach to a running JVM). Logging can be enabled using log4j and enabling logging at the org.hibernate (or deeper) level.
Hernan Amaya
Greenhorn

Joined: Jul 01, 2010
Posts: 7
I'm using Eclipse IDE and setting a breakpoint and debugging java code is straight forward, I didn't know how to see errors at Hibernate level, I have activated Log4j as a debug alternative and I have a better perspective now. Thanks.
Hernan Amaya
Greenhorn

Joined: Jul 01, 2010
Posts: 7
Though I have activated log4j I still can't determine what line or mapping has each error for example as I have configured default-access=method for each attribute in a class it says in the last exception I've gotten that there is a mapping that can't find its corresponding method to access the property to find this error I have to test each bean to see its methods or switch to property access, as you can see it would be better if I were told the exact mapping or line or *.hbm.xml where the error is. Is this possible?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Hibernate sessionFactoryBean in application context initialization