1

During upgrading to Hibernate 4 from its 3.v, I run into this problem occurred at the TC starting up.

... Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring/app-config.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
    ... 43 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring/app-config.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
    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:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
    ... 45 more
Caused by: java.lang.NullPointerException
    at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1415)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1355)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:184)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:314)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
    ... 55 more

And the sessionFactory in my configuration file is done as the following:

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="mappingResources">
        <list>
            <value>shippingCharge.hbm.xml</value>
        </list>
    </property>
    <property name="annotatedClasses">
        <list>
            <value>com.abc.myapp.account.domain.ProfileInfo</value>
            <value>com.abc.myapp.account.domain.Profile</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
            <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
            <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.DefaultComponentSafeNamingStrategy
            </prop>
        </props>
    </property>
    <!--  removed for hibernate 4. any replacement?
    <property name="eventListeners">
        <map>
            <entry key="merge">
                <bean
                    class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener" />
            </entry>
        </map>
    </property>
    -->
</bean>

How to solve this problem?

7
  • 2
    It may be foreign-key related. Maybe you could find some pointers here : stackoverflow.com/questions/9302993/… Commented Mar 1, 2012 at 7:01
  • add an answer if you find a solution based on @nico_ekito's advice. Commented Mar 1, 2012 at 17:28
  • Thanks for your information. In fact, I already read the post. I, however, don't think it is the same situation. This error occurs under a situation which my code hasn't been changed but Hibernate version from 3.6.8 to 4.1.0. I don't know whether the 4 version come with some special requirements on foreign key annotation configuration over the 3.6.8 version or not. Commented Mar 1, 2012 at 18:52
  • Please show your hbm file and your 2 domain classes. Commented Mar 1, 2012 at 19:54
  • The total number of domain classes are 25 which are mapped with annotations. It is not reality to show all domain classes here. The hbm file is something like the following: Commented Mar 2, 2012 at 6:50

4 Answers 4

2

Please replace org.springframework.orm.hibernate4.LocalSessionFactoryBuilder instead of org.springframework.orm.hibernate4.LocalSessionFactoryBean. This might help.

Sign up to request clarification or add additional context in comments.

1 Comment

Could you also include a reference link for more reading? Why does this solve the problem? Thanks.
1

it's maybe a spring issue. you can change <property name="annotatedClasses"> to <property name="packagesToScan" and try it again

Comments

0

this may be a stale jar file issue, i ran with the same error then in my log file i found Could not obtain connection metadata : DatabaseMetaData information is not known for server DB2/LINUXX8664SQL09010 by this version of JDBC driver
then i replaced my this project db2 jar files with one running project jars and it starts running smoothly

Comments

0

I was facing similar issue in my code. Then i tried updating the recent versions of DB2 jars into my server and the code started working. Try to update your DB2 jar.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.