Announcement Announcement Module
No announcement yet.
transaction management with two session factories Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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 :

                <bean id="txManager"
    		<property name="sessionFactory" ref="sessionFactory" />
    	<tx:advice id="txAdvice" transaction-manager="txManager">
    			<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" />
                 <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" 
    		<property name="mantisFeedbackDAO">
    			<ref bean="mantisFeedbackDAO"/>
                 <bean id="mantisFeedbackDAO" class="com.cmt.common.dao.MantisFeedbackDAO"
    		<property name="sessionFactory">
    			<ref bean="mantisSessionFactory" />
    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 for details on configuration.