Announcement Announcement Module
Collapse
No announcement yet.
why need to use Transaction Propogation advice for the SERVICE layer? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • why need to use Transaction Propogation advice for the SERVICE layer?

    I already googled and did my reading but still don't understand what is the purpose need to use AOP.config and tx.advise for service layer. can someone please elaborate to help me understand

    Code:
    	<!-- Spring JPA Transaction Manager -->
    	<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    	</bean>
    
    
    	<!-- AOP Transaction Injection -->
    	<aop:config>
    		<aop:pointcut id="courseManagerMethods"
    			expression="execution(*
    			com.teoh.server.service.CourseManager.*(..))" />
    		<aop:advisor advice-ref="txAdvice" pointcut-ref="courseManagerMethods" />
    	</aop:config>
    	
    	
        
        
    
    	<!-- Transaction Propogation advice for the SERVICE layer -->
    	<tx:advice id="txAdvice" transaction-manager="txManager">
    		<tx:attributes>
    			<tx:method name="persist*" propagation="REQUIRES_NEW" />
    			<tx:method name="testSpringMvcJpaIntegration*" propagation="REQUIRED" />
    			<tx:method name="*" propagation="SUPPORTS" read-only="true" />
    		</tx:attributes>
    	</tx:advice>

  • #2
    Because a pointcut isn't fine grained enough. You can select a class or a method with a certain name (or pattern). Next to that you might want to have get*/find* methods to be readonly, try that with a pointcut. You would either need to write multiple pointcuts with different tx-advices (one readonly, one for new transactions etc. etc.) so that would clutter your application configuration more then it would solve.

    Comment

    Working...
    X