-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: which sessionfactory to use for spring aop transaction ?
PostPosted: Sun Dec 27, 2009 11:15 pm 
Beginner
Beginner

Joined: Wed Oct 03, 2007 9:46 pm
Posts: 37
i have multiple sessionfactory because of using multiple datasource. different sessionfactory is used by osworkflow and different sessionfactory is used by projectService. I wanted to use @transactional for my project and i confuse wheather my configuration is correct? The xml is a working example and no error runnning.


I posted my applicationContext.xml and anyone comment on it and let me know



Code:
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xmlns:aop="http://www.springframework.org/schema/aop"

   xmlns:context="http://www.springframework.org/schema/context"

   xmlns:jee="http://www.springframework.org/schema/jee"

   xmlns:lang="http://www.springframework.org/schema/lang"

   xmlns:p="http://www.springframework.org/schema/p"

   xmlns:tx="http://www.springframework.org/schema/tx"

   xmlns:util="http://www.springframework.org/schema/util"

   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd

      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd

      http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd

      http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd

      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd

      http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">







<context:annotation-config/>

<context:component-scan
      base-package="com.company.project.projectcompany.services.IsUserCallerCondition_company_PreviousActionCaller" />

      <context:component-scan
      base-package="com.company.project.projectcompany.pages" />

<context:spring-configured />  <!-- activates injection into domain classes not managed by Spring -->



  <bean id="log4jInitialization" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="org.springframework.util.Log4jConfigurer"/>
<property name="targetMethod" value="initLogging"/>
<property name="arguments">
<list>
<value>classpath:log4j.xml</value>
</list>
</property>
</bean>

  <bean lazy-init="true" id="utilities"
    class="com.company.project.projectcompany.util.Utilities">
        </bean>




   <bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <!-- Map all *.hbm.xml files in pojo dir to the session factory -->
      <!--
        <property name="mappingDirectoryLocations">
         <list>
            <value>classpath:/com/myapp/pojo</value>
         </list>
      </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">false</prop>
            <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
            <!--<prop key="hibernate.hbm2ddl.auto">create</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>
         </props>
      </property>
      <property name="dataSource">
         <ref bean="dataSource" />
      </property>

      </bean>



    <bean id="dataSource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName">
         <value>oracle.jdbc.driver.OracleDriver</value>
      </property>
                <!-- xdb is defined by running the hsqldb as xdb (see above) -->
      <property name="url">
         <value>jdbc:oracle:thin:@192.168.0.23:1521:appsdev</value>
      </property>
      <property name="username">
         <value>testonly</value>
      </property>
      <property name="password">
         <value>testonly</value>
      </property>
   </bean>









<bean id="workflowStore"
class="com.opensymphony.workflow.spi.hibernate3.SpringHibernateWorkflowStore">
   <property name="sessionFactory"><ref bean="sessionFactory"/></property>
   <!--
   Optional PropertySet delegate, in case you want
    to use another PropertySet store that is not HibernateStore
   <property name="propertySetDelegate">
        <ref local="propertySetDelegate"/>
    </property>
   -->
     <property name="propertySetDelegate">
            <bean id="propertySetDelegate" class="ahxu.workflow.hibernate3.DefaultHibernatePropertySetDelegate">
                <property name="sessionFactory"><ref local="sessionFactory"/></property>
            </bean>
        </property>
  </bean>

  <bean id="workflowFactory"
        class="com.opensymphony.workflow.spi.hibernate.SpringWorkflowFactory"
        init-method="init">
    <property name="resource"><value>workflows.xml</value></property>
    <property name="reload"><value>true</value></property>
  </bean>


  <bean id="osworkflowConfiguration"
        class="com.opensymphony.workflow.config.SpringConfiguration">
    <property name="store"><ref local="workflowStore"/></property>
   <property name="factory"><ref local="workflowFactory"/></property>
  </bean>


  <bean id="workflowTypeResolver"
        class="com.opensymphony.workflow.util.SpringTypeResolver">
    <!--
    Here you can inject custom resolver for business logic
   <property name="conditions">
      <map>
       <entry key="beanshell">
        <value>mypackage.MyBeanShellCustomCondition</value></entry>
     </map>
   </property>
   -->
  </bean>





  <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager"><ref local="transactionManager"/></property>
<property name="transactionAttributes">
  <props>
   <prop key="*">PROPAGATION_REQUIRED</prop>
  </props>
</property>
</bean>

<bean id="workflow" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="singleton">
  <value>false</value>
</property>
<property name="proxyInterfaces">
  <value>ahxu.osworkflow.example.WebWorkflow</value>
</property>
<property name="interceptorNames">
  <list>
   <value>transactionInterceptor</value>
   <value>workflowTarget</value>
  </list>
</property>
</bean>

<bean id="workflowTarget" class="ahxu.osworkflow.example.WebBasicWorkflow" scope="prototype">

<property name="configuration"><ref local="osworkflowConfiguration"/></property>
</bean>


    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" >
            <ref local="sessionFactory"/>
        </property>
    </bean>









<!-- CACHE config -->
<bean id="cache" abstract="true"
class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="cacheManager" ref="cacheManager" />
</bean>
<bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml" />
</bean>
<bean id="cacheProviderCacheManagerInjector" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="staticMethod" value="com.company.project.projectcompany.services.ExternalEhCacheProvider.setCacheManager"/>
    <property name="arguments">
        <list>
            <ref bean="cacheManager"/>
        </list>
    </property>
</bean>




















   <bean id="dataSourceHRMS"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName">
         <value>oracle.jdbc.driver.OracleDriver</value>
      </property>
                <!-- xdb is defined by running the hsqldb as xdb (see above) -->
      <property name="url">
         <value>jdbc:oracle:thin:@192.168.0.23:1521:appsprd</value>
      </property>
      <property name="username">
         <value>test2</value>
      </property>
      <property name="password">
         <value>test2</value>
      </property>
   </bean>



       <bean id="sessionFactoryHRMS"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <!-- Map all *.hbm.xml files in pojo dir to the session factory -->
      <!--
        <property name="mappingDirectoryLocations">
         <list>
            <value>classpath:/com/myapp/pojo</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.cglib.use_reflection_optimizer">true</prop>
            <!--<prop key="hibernate.hbm2ddl.auto">create</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>
         </props>
      </property>
      <property name="dataSource">
         <ref bean="dataSourceHRMS" />
      </property>

      </bean>



    <!-- Hibernate DAO implementation.  Transactions (AOP) have been applied at the service layer not here -->
    <bean id="hrmsappsdao" class="com.company.project.projectcompany.services.HRMSAPPSHibernateDao" >
        <property name="hibernateTemplate">
            <bean class="org.springframework.orm.hibernate3.HibernateTemplate">
                <property name="sessionFactory" ref="sessionFactoryHRMS"/>


                 <property name="flushMode">
                         <bean class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
                         <property name="staticField" value="org.springframework.orm.hibernate3.HibernateAccessor.FLUSH_COMMIT"/>
                         </bean>
                 </property>
            </bean>
        </property>

    </bean>


    <!-- Hibernate DAO implementation.  Transactions (AOP) have been applied at the service layer not here -->
    <bean id="projectdao" class="com.company.project.projectcompany.services.projectHibernateDao" >
        <property name="hibernateTemplate">
            <bean class="org.springframework.orm.hibernate3.HibernateTemplate">
                <property name="sessionFactory" ref="annotatedsessionFactory"/>


                 <property name="flushMode">
                         <bean class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
                         <property name="staticField" value="org.springframework.orm.hibernate3.HibernateAccessor.FLUSH_COMMIT"/>
                         </bean>
                 </property>
            </bean>
        </property>

    </bean>



    <bean id="transactionManagerAnnotated" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" >
            <ref local="annotatedsessionFactory"/>
        </property>
    </bean>




        <bean id="projectService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
        <property name="transactionManager" ref="transactionManagerAnnotated"/>
        <property name="target">
            <bean class="com.company.project.projectcompany.services.ProjectServiceImpl" init-method="init">

                 <property name="hrmsappsdao" ref="hrmsappsdao"/>
                   <property name="projectdao" ref="projectdao"/>
                    <property name="workflow" ref="workflow"/>
            </bean>
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="store*">PROPAGATION_REQUIRED</prop>
                <prop key="update*">PROPAGATION_REQUIRED</prop>
                <prop key="remove*">PROPAGATION_REQUIRED</prop>
                <prop key="bulkUpdate*">PROPAGATION_REQUIRED</prop>
                <prop key="*">PROPAGATION_SUPPORTS,readOnly</prop>
            </props>
        </property>
    </bean>








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


        <property name="packagesToScan" value="com.company.project.projectcompany.model" >
        </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.company.project.projectcompany.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>











<bean id="rockerCacheAspect" class="com.company.project.projectcompany.services.CacheAspect" >

<property name="cache">
<bean id="bandCache" parent="cache">
<property name="cacheName" value="methodCache" />
</bean>
</property>
</bean>

<!--
<bean id="dummy" class="com.company.project.projectcompany.services.DummyClass"/>
-->



<aop:config>

<aop:pointcut id="readOperation" expression=
"execution(* com.company.project.projectcompany.services.ProjectServiceImpl.*getWorkflowForAgentAllCached(..))"
/>
<aop:pointcut id="exitOperation" expression=
"execution(void com.company.project.projectcompany.services.ProjectServiceImpl.resetWorkflowForAgentAllCached())"
/>

<aop:aspect id="dummyCacheAspect" ref="rockerCacheAspect">
<aop:around pointcut-ref="readOperation" method="cacheObject" />
<aop:after pointcut-ref="exitOperation" method="flush" />
</aop:aspect>
</aop:config>


<bean id="rockerHRMSCacheAspect" class="com.company.project.projectcompany.services.CacheAspect" >

<property name="cache">
<bean id="bandHRMSCache" parent="cache">
<property name="cacheName" value="methodHRMSReadOnlyCache" />
</bean>
</property>
</bean>


<aop:config>

<aop:pointcut id="readOperationHRMS" expression=
"execution(* com.company.project.projectcompany.services.ProjectServiceImpl.*TotalHRMSUsers(..))"
/>
<aop:pointcut id="exitOperationHRMS" expression=
"execution(void com.company.project.projectcompany.services.ProjectServiceImpl.resetHRMSReadOnlyAllCached())"
/>

<aop:aspect id="dummyHRMSCacheAspect" ref="rockerHRMSCacheAspect">
<aop:around pointcut-ref="readOperationHRMS" method="cacheObject" />
<aop:after pointcut-ref="exitOperationHRMS" method="flush" />
</aop:aspect>
</aop:config>







</beans>













Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.