Announcement Announcement Module
Collapse
No announcement yet.
sessionFactory NullPointerException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • sessionFactory NullPointerException

    For some reason (I'm not able to reproduce the error yet), on our production server, after some time, a page stops working and instead an error report is shown.

    A NullPointerException is thrown, but I do not see any of my own classes in there, so I'm guessing I made a configuration error
    But does somebody recognize the error, or know where I should search? (or perhaps how to reproduce?).

    Below is the top and bottom part of the stacktrace.
    Thanks in advance,
    Jonne.

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource' defined in ServletContext resource [/WEB-INF/spring-gis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/spring-gis.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-gis.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
    
    ...
    
    root cause
    
    java.lang.NullPointerException
    	org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.closeConnection(LocalDataSourceConnectionProvider.java:96)
    	org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:113)
    	org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073)
    	org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298)
    	org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:816)
    	org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:734)
    	org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1367)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1333)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:471)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	java.security.AccessController.doPrivileged(Native Method)
    
    ...
    
    java.security.AccessController.doPrivileged(Native Method)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:217)
    	org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:168)
    	org.springframework.context.support.AbstractApplicationContext.initMessageSource(AbstractApplicationContext.java:628)
    	org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)
    	org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
    	org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
    	org.springframework.web.context.ContextLoaderServlet.init(ContextLoaderServlet.java:81)
    	javax.servlet.GenericServlet.init(GenericServlet.java:212)
    	org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
    	org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
    	org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
    	org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
    	org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    	org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    	org.apache.catalina.startup.Catalina.start(Catalina.java:566)
    	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	java.lang.reflect.Method.invoke(Method.java:585)
    	org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    	org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

  • #2
    It looks like it is trying to create a SessionFactory... Why?! You aren't recreated a new ApplicationContext each time you need something!

    Comment


    • #3
      Sorry, forgot to mention that we use
      Spring version 2.5.3.

      Comment


      • #4
        Hi Marten,

        Thanks for you reply. I do not understand why it is trying to recreate the session factory.
        Below is my xml sessionFactory definition.

        All our other beans refer to the sessionFactory like this:
        Code:
        <property name="sessionFactory" ref="sessionFactory" />
        Code:
        	<bean id="sessionFactory"
        		class="nl.my.package.system.model.MyLocalSessionFactoryBean">
        		<property name="dataSource" ref="dataSource" />
        		<property name="mappingResourcePatterns">
        			<list>
        				<value>nl/my/package/domain/generated/*.hbm.xml</value>
        				<value>nl/my/package/module/model/Test.hbm.xml</value>
        			</list>
        		</property>
        		<property name="hibernateProperties">
        			<props>
        				<prop key="hibernate.dialect">
        					org.hibernate.dialect.SQLServerDialect
        				</prop>
        				<prop key="hibernate.show_sql">false</prop>
        				<prop key="hibernate.format_sql">true</prop>
        			</props>
        		</property>
        	</bean>

        Comment


        • #5
          Today I've been able to reproduce the error, but only at startup.
          We're using a custom datasource with a getConnection() method that
          returns our.Database.getConnection(). This our.Database class is a left-over from the old architecture of the application.

          The error can be reproduced by returning null the very first time. Then, services will not get initialized and the error will never go away.
          I modified the code to ensure that it will block and can never return null.

          I could also have used the following:

          <bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
          <property name="driverClassName"
          value="com.microsoft.sqlserver.jdbc.SQLServerDrive r" />
          <property name="url"
          value="jdbc:sqlserver://???:1433;databaseName=???" />
          <property name="username" value="???" />
          <property name="password" value="???" />
          </bean>

          But I have to figure out two things:
          1) what will happen here if the database cannot be accessed for some reason during startup?
          2) I think the reason we did not do it like this is that the databaseName,
          username etc is stored in a properties file. (ok, i bet this is a bad reason

          Comment


          • #6
            Externalizing properties can be quite easy with spring. Simply configure a PropertyPlaceHolderConfigurer and you are good to go. Next to that don't use the DriverManagerDataSource in a production environment you want to use a ConnectionPool for that.

            Comment

            Working...
            X