Announcement Announcement Module
Collapse
No announcement yet.
transaction management with two session factories Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • transaction management with two session factories

    I have on e service FeedbackService. I have defined a pointcut on all methods of this service. this pointcut referes to a transaction advice (txAdvice) which points to DB1.

    2) I also have a mantisFeedbackDAO defined in FeedbackService which has a sessionfactory pointing to DB2.

    Please find my configuration as follows :

    Code:
                <bean id="txManager"
    		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory" ref="sessionFactory" />
    	</bean>
    	<tx:advice id="txAdvice" transaction-manager="txManager">
    		<tx:attributes>
    			<tx:method name="*" propagation="REQUIRED" />
    			<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
    			<tx:method name="count*" propagation="SUPPORTS" read-only="true" />
    			<tx:method name="validate*" propagation="SUPPORTS" read-only="true" />
    			<tx:method name="find*" propagation="SUPPORTS"	read-only="true" />
    			<tx:method name="login" propagation="SUPPORTS" read-only="true" />
    		</tx:attributes>
    	</tx:advice>
                 <aop:pointcut id="serviceOperationMantis" expression="execution(* com.cmt.common.service.FeedbackService.*(..))" />
                 <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperationMantis" />
                  <bean name="feedbackService" class="com.cmt.common.service.FeedbackService" 
    		scope="singleton">
    		<property name="mantisFeedbackDAO">
    			<ref bean="mantisFeedbackDAO"/>
    		</property>
    	</bean>
                 <bean id="mantisFeedbackDAO" class="com.cmt.common.dao.MantisFeedbackDAO"
    		scope="singleton">
    		<property name="sessionFactory">
    			<ref bean="mantisSessionFactory" />
    		</property>
    	</bean>
    As I said above in point no. 2 "mantisSessionFactory" is pointing to DB2.

    Now when I call any method in feedbackService it will start the transaction using transaction manager - "txManager". But when I give call to a method in mantisFeedbackDAO through feedbackservice,it is performing operations on DB2. So how does this work?? Because when we threw a RuntimeException from this DAO method Spring didn't roll-back the transaction.
    Does this kind of configuration make any sense as far as Spring's Transaction Management is concerned??

  • #2
    In case you are using 2 databases then for transactions to work you will have to use JTA transactions. You will have to configure 2 XA datasource which the 2 Hibernate session factories will use. Please refer to section 12.2.8 in http://static.springsource.org/sprin...rence/orm.html for details on configuration.

    Comment

    Working...
    X