views:

82

answers:

1

(connected to db call abc)--->datasource1 ---> LocalSessionFactoryBean --->transactionManager1

(connected to db call abc)--->datasource1----->AnnotationSessionFactoryBean -->transactionManager2

the reason i have 2 sessionfactory is because one is used by 3rd party osworkflow library and latter use by my application

since both are connection to same "datasource1" (same database), i can use either one as service layer transactionmanager right ?

    <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>

I get error

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  A: 

Use one SessionFactory

AnnotationSessionFactoryBean extends LocalSessionFactoryBean, so it has all of its capabilities.

Bozho
the reason is the 3rdparty osworkflow using .hbm mapping, while my app using annotation mapping. how to combined into one?
cometta
just use AnnotationSessionFactoryBean. It has the capabilities of LocalSessionFactoryBean
Bozho