Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-1758

Hibernate LocalSessionFactoryBean Does Not Allow a Lazy DataSource

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.2.6
    • Fix Version/s: None
    • Component/s: Data
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      Despite setting lookup OnStartup to false and providing a proxyInterface, the LocalSessionFactoryBean still attempts to retrieve the dataSource on startup. This is because it attempts to grab a connection while it starts up.

      Here's the configuration:

      <property name="dataSource">
      <bean class="org.springframework.jndi.JndiObjectFactoryBean">
      <property name="jndiName" value="jdbc/CIEPortalApps" />
      <property name="resourceRef" value="true" />
      <property name="lookupOnStartup" value="false" />
      <property name="proxyInterface" value="javax.sql.DataSource" />
      </bean>
      </property>

      Here's the stack trace showing that it attempts to initalize it, but can't since the JNDI name doesn't exist yet:

      2006-03-03 14:10:32,460 WARN (org.apache.naming.NamingContext:801) - Unexpected exception resolving reference
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceImpl' defined in class path resource [mil/jfcom/cie/directorymanagement/conf/spring/service.xml]: Can't resolve reference to bean 'databaseService' while setting property 'databaseService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.orm.hibernate.HibernateTransactionManager#1d98a' defined in class path resource [mil/jfcom/cie/directorymanagement/conf/spring/hibernate.xml]: Can't resolve reference to bean 'hibernateSessionFactory' while setting property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateSessionFactory' defined in class path resource [mil/jfcom/cie/directorymanagement/conf/spring/hibernate.xml]: Initialization of bean failed; nested exception is java.lang.reflect.UndeclaredThrowableException: null
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.orm.hibernate.HibernateTransactionManager#1d98a' defined in class path resource [mil/jfcom/cie/directorymanagement/conf/spring/hibernate.xml]: Can't resolve reference to bean 'hibernateSessionFactory' while setting property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateSessionFactory' defined in class path resource [mil/jfcom/cie/directorymanagement/conf/spring/hibernate.xml]: Initialization of bean failed; nested exception is java.lang.reflect.UndeclaredThrowableException: null
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateSessionFactory' defined in class path resource [mil/jfcom/cie/directorymanagement/conf/spring/hibernate.xml]: Initialization of bean failed; nested exception is java.lang.reflect.UndeclaredThrowableException: null
      java.lang.reflect.UndeclaredThrowableException
      at $Proxy0.getConnection(Unknown Source)
      at org.springframework.orm.hibernate.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:76)
      at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:73)
      at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1155)
      at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:789)
      at org.springframework.orm.hibernate.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:543)
      at org.springframework.orm.hibernate.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:477)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1059)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:363)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:176)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:105)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1013)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:147)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:96)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1013)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:176)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:105)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1013)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:275)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:320)
      at mil.jfcom.cie.portal.AbstractSpringObjectFactory.getObject(AbstractSpringObjectFactory.java:76)
      at mil.jfcom.cie.portal.AbstractSpringObjectFactory.getObjectInstance(AbstractSpringObjectFactory.java:59)
      at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:129)
      at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
      at org.apache.naming.NamingContext.lookup(NamingContext.java:791)
      at org.apache.naming.NamingContext.lookup(NamingContext.java:151)
      at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans(GlobalResourcesLifecycleListener.java:155)
      at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans(GlobalResourcesLifecycleListener.java:160)
      at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans(GlobalResourcesLifecycleListener.java:125)
      at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.lifecycleEvent(GlobalResourcesLifecycleListener.java:97)
      at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
      at org.apache.catalina.core.StandardServer.start(StandardServer.java:2306)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
      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:287)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)
      Caused by: javax.naming.NameNotFoundException: Name comp is not bound in this Context
      at org.apache.naming.NamingContext.lookup(NamingContext.java:768)
      at org.apache.naming.NamingContext.lookup(NamingContext.java:151)
      at org.apache.naming.SelectorContext.lookup(SelectorContext.java:136)
      at javax.naming.InitialContext.lookup(InitialContext.java:351)
      at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:123)
      at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:85)
      at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:121)
      at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:146)
      at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:86)
      at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:104)
      at org.springframework.jndi.JndiObjectTargetSource.getTarget(JndiObjectTargetSource.java:121)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:150)
      ... 51 more
      2006-03-03 14:10:32,464 ERROR (org.apache.catalina.mbeans.GlobalResourcesLifecycleListener:127) - Exception processing Global JNDI Resources
      javax.naming.NamingException: Error creating bean with name 'serviceImpl' defined in class path resource [mil/jfcom/cie/directorymanagement/conf/spring/service.xml]: Can't resolve reference to bean 'databaseService' while setting property 'databaseService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.orm.hibernate.HibernateTransactionManager#1d98a' defined in class path resource [mil/jfcom/cie/directorymanagement/conf/spring/hibernate.xml]: Can't resolve reference to bean 'hibernateSessionFactory' while setting property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateSessionFactory' defined in class path resource [mil/jfcom/cie/directorymanagement/conf/spring/hibernate.xml]: Initialization of bean failed; nested exception is java.lang.reflect.UndeclaredThrowableException: null
      at org.apache.naming.NamingContext.lookup(NamingContext.java:803)
      at org.apache.naming.NamingContext.lookup(NamingContext.java:151)
      at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans(GlobalResourcesLifecycleListener.java:155)
      at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans(GlobalResourcesLifecycleListener.java:160)
      at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans(GlobalResourcesLifecycleListener.java:125)
      at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.lifecycleEvent(GlobalResourcesLifecycleListener.java:97)
      at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
      at org.apache.catalina.core.StandardServer.start(StandardServer.java:2306)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
      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:287)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)

        Attachments

          Activity

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              jrduncans Stephen Duncan Jr
              Last updater:
              Trevor Marshall
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                12 years, 26 weeks, 1 day ago