Announcement Announcement Module
No announcement yet.
why need to use Transaction Propogation advice for the SERVICE layer? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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

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

  • #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.