Menu

Hibernate SessionFactory setup with Spring

fido
2004-06-18
2004-06-18
  • fido

    fido - 2004-06-18

    Hi

    I'm having problems setting the Hibernate mapping files in my applicationContext.xml file. I find it rather strange: It seems like Spring can't find one of my mapping files, even though the url is correct.. When I remove the one evil mapping-reference, wich Spring is not able to find, my testCase works perfectly fine..

    My stacktrace follows:

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/corporater/spring/applicationContext.xml]: Initialization of bean failed; nested exception is java.io.FileNotFoundException: Could not open class path resource [com/corporater/dir/Organisation.hbm.xml"]
    java.io.FileNotFoundException: Could not open class path resource [com/corporater/dir/Organisation.hbm.xml"]
        at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:84)
        at org.springframework.orm.hibernate.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:322)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:801)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:249)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:177)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:159)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:177)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:268)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:58)
        at com.corporater.spring.ApplicationContextFactory.getApplicationContext(ApplicationContextFactory.java:47)
        at com.corporater.Main.<init>(Main.java:31)
        at com.corporater.Main.main(Main.java:46)
    java.lang.NullPointerException
        at com.corporater.Main.<init>(Main.java:31)
        at com.corporater.Main.main(Main.java:46)
    Exception in thread "main"

    The reference in applicationContext.xml:

    <!-- Hibernate SessionFactory -->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
            <property name="dataSource"><ref local="dataSource"/></property>
           
            <!-- Must references all OR mapping files. -->
            <property name="mappingResources">
                <list>
                   
                    <value>com/corporater/Scorecard.hbm.xml</value>
                    <value>com/corporater/Perspective.hbm.xml</value>
                    <value>com/corporater/Focusarea.hbm.xml</value>
                    <value>com/corporater/Kpi.hbm.xml</value>
                    <value>com/corporater/KpiLimit.hbm.xml</value>
                    <value>com/corporater/dir/Organisation.hbm.xml"</value>
                   
                </list>
            </property>
           
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">net.sf.hibernate.dialect.SQLServerDialect</prop>
                                   
                    <!-- C3PO Connection pooling: -->
                    <prop key="hibernate.connection.provider_class">net.sf.hibernate.connection.C3P0ConnectionProvider</prop>
                    <prop key="hibernate.c3p0.max_size">4</prop>
                    <prop key="hibernate.c3p0.min_size">2</prop>
                    <prop key="hibernate.c3p0.timeout">5000</prop>
                    <prop key="hibernate.c3p0.max_statements">100</prop>
                    <prop key="hibernate.c3p0.idle_test_period">3000</prop>
                    <prop key="hibernate.c3p0.acquire_increment">2</prop>
                    <!-- <prop key="hibernate.c3p0.validate">false</prop> -->
                   
                    <!-- Miscellaneus Settings -->
                    <prop key="hibernate.show_sql">false</prop>       
                                   
                    <prop key="hibernate.jdbc.batch_size">0</prop>
                   
                    <prop key="hibernate.use_outer_join">true</prop>
                   
                    <prop key="hibernate.max_fetch_depth">1</prop>
                   
                    <prop key="hibernate.cache.use_query_cache">true</prop>
                   
                    <!--<prop key="hibernate.cache.provider_class">net.sf.hibernate.cache.OSCacheProvider</prop> -->
                    <!-- For Hibernates EHCache, change to: net.sf.ehcache.hibernate.Provider -->
                   
                </props>
            </property>
        </bean>

    Organisation.hbm.xml is located at:
    C:\test_hibernate\src\bin\com\corporater\dir

    I've tried moving around the other mapping files wich is originally located at:
    C:\test_hibernate\src\bin\com\corporater\
    but Spring seems to find these wherever we put them

    I hope someone can help with this strange behavior from Spring ( or probably me.. ).

    cheers Fido

     
    • fido

      fido - 2004-06-18

      I fixed my problems by replacing
      <property name="mappingResources"> with mappingDirectoryLocations

       
    • Krishnan Anantheswaran

      Actually I see a quote at the end of the inclusion of the problematic mapping file. This could have been the reason for the issue.

      <value>com/corporater/dir/Organisation.hbm.xml"</value>

       

Log in to post a comment.

MongoDB Logo MongoDB