Announcement Announcement Module
Collapse
No announcement yet.
JndiObjectFactoryBean lookupOnStartup not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JndiObjectFactoryBean lookupOnStartup not working

    Hi,

    I'm having problems with getting lookupOnStart to work. I'm not sure if my understanding of what it's supposed to do is correct or not.

    I want to be able to deploy my webapp without one of the datasources being available yet, so far I've got this in my applicationContext

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName">
    <value>testdatabase</value>
    </property>
    <property name="lookupOnStartup">
    <value>false</value>
    </property>
    <property name="proxyInterface">
    <value>javax.sql.DataSource</value>
    </property>
    </bean>

    but when I try to deploy my web app without the datasource being available I get this exception

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in class path resource [au/com/test/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.reflect.UndeclaredThrowableException
    java.lang.reflect.UndeclaredThrowableException
    at $Proxy25.getConnection(Unknown Source)
    at org.springframework.orm.hibernate3.LocalDataSource ConnectionProvider.getConnection(LocalDataSourceCo nnectionProvider.java:81)
    at org.hibernate.cfg.SettingsFactory.buildSettings(Se ttingsFactory.java:72)
    at org.hibernate.cfg.Configuration.buildSettings(Conf iguration.java:1881)
    at org.hibernate.cfg.Configuration.buildSessionFactor y(Configuration.java:1174)
    at org.springframework.orm.hibernate3.LocalSessionFac toryBean.newSessionFactory(LocalSessionFactoryBean .java:825)

    Can someon please help explain what's happening?

    Thanks.

  • #2
    I doubt turning lookupOnStartup off does anything for Hibernate because Hibernate will try to get the connection when SessionFactory is built. In other words, I don't think you can start Hibernate without a DataSource.

    Comment


    • #3
      Just a thought, would setting lazy attribute on LocalSessionFactoryBean help?

      Comment


      • #4
        As long as no other object that isn't lazy-initialized references it should be fine. But I imagine you're DAOs and transaction manager would have to be lazy initialized too.

        However, since session factories can take time to startup, the first time you go access your Hibernate functionality might have a significant delay.

        Comment


        • #5
          Hey guys,

          Thanks for the feedback.

          I've tried set lazy-init on the transactionManager and DAOs but then I just get nested exceptions that cascades back to the datasource not being available

          Error: weblogic.management.DeploymentException: Error creating bean with name 'dataSource' defined in class path resource [au/com/test/applicationContext.xml]: Initialization of bean failed; nested exception ...

          I even set <beans default-lazy-init="true"> but that still doesn't work.

          dejanp is there anyway that I can get hibernate to do lazy lookup of the datasource or something? I just want to be able to have my webapp deployed and then handle the exception at a later stage.

          Thanks.

          Comment


          • #6
            Afaik, no. Hibernate needs a connection to create a SessionFactory and that's it. But on the other hand default-lazy-init="true" should work. Can you post your app context please?

            Comment


            • #7
              Here's a copy of my applicationContext.xml

              <?xml version="1.0" encoding="UTF-8"?>
              <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

              <beans>

              <!-- Datasources -->
              <bean id="testDataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
              <property name="jndiName">
              <value>db1</value>
              </property>
              <property name="resourceRef">
              <value>false</value>
              </property>
              </bean>

              <bean id="testStagingDataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
              <property name="jndiName">
              <value>db2</value>
              </property>
              <property name="lookupOnStartup">
              <value>false</value>
              </property>
              <property name="proxyInterface">
              <value>javax.sql.DataSource</value>
              </property>

              <property name="resourceRef">
              <value>false</value>
              </property>
              </bean>

              <!-- SessionFactories -->
              <bean id="testSessionFactory" class="au.com.test.cms.CmsSessionFactoryBean">
              <property name="dataSource" ref="testDataSource"/>
              <property name="mappingResources" ref="testMappingResources"/>
              <property name="hibernateProperties">
              <props>
              <prop key="hibernate.dialect">org.hibernate.dialect.Orac le9Dialect</prop>
              <prop key="hibernate.show_sql">true</prop>
              <prop key="hibernate.query.factory_class">org.hibernate. hql.classic.ClassicQueryTranslatorFactory</prop>
              <prop key="hibernate.use_sql_comments">false</prop>
              </props>
              </property>
              </bean>

              <bean id="testStagingSessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
              <property name="dataSource" ref="testStagingDataSource"/>
              <property name="mappingResources">
              <list>
              <value>au/com/test/data/Recommendation.hbm.xml</value>
              </list>
              </property>
              <property name="hibernateProperties">
              <props>
              <prop key="hibernate.dialect">org.hibernate.dialect.Orac le9Dialect</prop>
              <prop key="hibernate.show_sql">true</prop>
              <prop key="hibernate.query.factory_class">org.hibernate. hql.classic.ClassicQueryTranslatorFactory</prop>
              <prop key="hibernate.use_sql_comments">false</prop>
              </props>
              </property>
              </bean>

              <!-- Resources -->
              <bean id="testMappingResources" class="org.springframework.beans.factory.config.Li stFactoryBean">
              <property name="sourceList">
              <list>
              <value>au/com/test/data/Weblink.hbm.xml</value>
              <value>au/com/test/data/Instructions.hbm.xml</value>
              </list>
              </property>
              </bean>

              <!-- Transaction manager -->
              <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
              <property name="sessionFactory" ref="testSessionFactory"/>
              </bean>

              <bean id="transactionManagerStaging" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
              <property name="sessionFactory" ref="testStagingSessionFactory"/>
              </bean>

              <bean id="testService" class="au.com.test.service.MobileWebServiceImpl">
              <property name="instructionsDao" ref="instructionsDao"/>
              <property name="recommendationDao" ref="recommendationDao"/>
              <property name="weblinkDao" ref="weblinkDao"/>
              </bean>

              <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailS enderImpl">
              <property name="host">
              <value>mail.test.com.au</value>
              </property>
              <property name="javaMailProperties">
              <props>
              <prop key="mail.smtp.connectiontimeout">10000</prop>
              <prop key="mail.smtp.timeout">60000</prop>
              </props>
              </property>
              </bean>

              <bean id="mailMessage" class="org.springframework.mail.SimpleMailMessage" >
              <property name="from">
              <value>[email protected]</value>
              </property>
              <property name="to">
              <value>[email protected]</value>
              </property>
              <property name="subject">
              <value>Mail test</value>
              </property>
              </bean>

              <bean id="recommendationDao" class="au.com.test.dao.hibernate.RecommendationDao Impl">
              <property name="sessionFactory" ref="testStagingSessionFactory"/>
              </bean>

              <bean id="instructionsDao" class="au.com.test.dao.hibernate.InstructionsDaoIm pl">
              <property name="sessionFactory" ref="testSessionFactory"/>
              </bean>

              <bean id="weblinkDao" class="au.com.test.dao.hibernate.WeblinkDaoImpl">
              <property name="sessionFactory" ref="testSessionFactory"/>
              </bean>

              </beans>

              I've tried setting the 'transactionManagerStaging' to lazy-init="true" and as well as the daos but to no avail...
              Last edited by lazy_p; Oct 16th, 2006, 03:06 AM.

              Comment


              • #8
                Actually I believe my problem comes from the fact that the org.springframework.web.servlet.handler.SimpleUrlH andlerMapping is being initialized which then tries to initialize the controller which in turn initializes my service and cacades back down to the datasource which is unavailable.

                Does this seem to make more sense about my dilema?

                Comment

                Working...
                X