transactionmanager使用相同的数据源

时间:2010-01-06 08:17:45

标签: java hibernate spring datasource sessionfactory

(连接到db call abc)---> datasource1 ---> LocalSessionFactoryBean ---> transactionManager1

(连接到db call abc)---> datasource1 -----> AnnotationSessionFactoryBean - > transactionManager2

我有2个sessionfactory的原因是因为一个被第三方osworkflow库使用而后者被我的应用程序使用

由于两者都连接到相同的“datasource1”(同一个数据库),我可以使用其中任何一个作为服务层事务管理器吗?

    <bean id="annotatedsessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">


        <property name="packagesToScan" value="com.company.model" >
        </property>


 <property name="mappingResources">
            <list>
                <value>com/opensymphony/workflow/spi/hibernate3/HibernateCurrentStep.hbm.xml</value>
                <value>com/opensymphony/workflow/spi/hibernate3/HibernateHistoryStep.hbm.xml</value>
                 <value>com/opensymphony/workflow/spi/hibernate3/HibernateWorkflowEntry.hbm.xml</value>
                  <value>ahxu/workflow/hibernate3/PropertySetItemImpl.hbm.xml</value>
                   <value>com/opensymphony/user/provider/hibernate3/ahxu/impl/HibernateGroupImpl.hbm.xml</value>
                   <value>com/opensymphony/user/provider/hibernate3/ahxu/impl/HibernateUserImpl.hbm.xml</value>
            </list>
        </property>


        <property name="hibernateProperties">
            <props>

                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.use_sql_comments">true</prop>
                <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
          <!--      <prop key="hibernate.hbm2ddl.auto">update</prop>   -->
                <prop key="hibernate.c3p0.min_size">5</prop>
                <prop key="hibernate.c3p0.max_size">20</prop>
                <prop key="hibernate.c3p0.timeout">1800</prop>
                <prop key="hibernate.c3p0.max_statements">50</prop>
                <prop key="hibernate.cache.provider_class">
                      com.services.ExternalEhCacheProvider
                </prop>
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <prop key="hibernate.cache.use_query_cache">true</prop>



            </props>
        </property>
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>

    </bean>

我收到错误

org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'annotatedsessionFactory' defined in ServletContext resource [/WEB-INF/ap
plicationContext.xml]: Invocation of init method failed; nested exception is jav
a.lang.NullPointerException
        at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory$1.run(AbstractAutowireCapableBeanFactory.java:409)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:380)

1 个答案:

答案 0 :(得分:1)

使用一个SessionFactory

AnnotationSessionFactoryBean扩展LocalSessionFactoryBean,因此它具有所有功能。