Bean-Managed Transaction Suspension in J2EE

Bean-Managed Transaction Suspension in J2EE

TransactionManager Usage in the Spring Framework

The techniques described above are used extensively in the popular Spring framework for transactional proxies. You should be aware that every time you configure Spring's TransactionProxyFactoryBean with PROPAGATION_REQUIRES_NEW or PROPAGATION_NOT_SUPPORTED, transaction attributes, and JtaTransactionManager, Spring uses JTA's TransactionManager for transaction suspension and resumption. Spring is smart enough--sometimes too smart for my taste--to discover TransactionManager in your container, even if you don't specify it. For example, you can supply a JNDI name for UserTransaction when defining JtaTransactionManager in a Spring application context and it will "autodetect" TransactionManager if UserTransaction also implements it; as shown above, this is true for WebLogic, Orion, and Oracle OC4J.



Sometimes, this could be undesirable, especially if you want to stay strictly within a J2EE/EJB specification and ensure complete portability across all J2EE containers. Sometimes, as we've seen above, there could be issues with programmatic transaction suspend and resume, although Spring knows how to work around some of them, at least the issue described above with marking transaction for rollback before suspending in WebLogic. In this case, you can set the autodetectTransactionManager property to false when configuring JtaTransactionManager. If you do so, any attempt to use PROPAGATION_REQUIRES_NEW or PROPAGATION_NOT_SUPPORTED transactional attributes should fail with TransactionSuspensionNotSupportedException, but PROPAGATION_REQUIRED, PROPAGATION_SUPPORTS, PROPAGATION_MANDATORY, and PROPAGATION_NEVER should work normally. This corresponds to the functionality provided by the JTA UserTransaction and is guaranteed to work in any J2EE-compatible container.

Below is the transaction manager definition in a Spring application context with TransactionManager autodetect disabled.




<bean id="transactionManager" class=

"org.springframework.transaction.jta.JtaTransactionManager">

  <property name="userTransactionName">

    <value>javax.transaction.UserTransaction</value>

  </property>

  <property name="autodetectTransactionManager">

    <value>false</value>

  </property>

</bean>



Conclusion

Support for the JTA TransactionManager interface is not required by the J2EE specification, but since J2EE uses JTA as its underlying transaction infrastructure, almost all J2EE servers expose it as an extension to J2EE. There are some known issues with compatibility, and under certain circumstances, container-specific code can be used to work around it. Nevertheless, using TransactionManager in J2EE is a powerful feature if you need to implement programmatic transaction suspension. Just always test it first in your chosen J2EE server.

Resources

  • Java Transaction API
  • Spring (see also CodeZoo: Spring)
  • WebLogic 8
  • Orion 2
  • Oracle OC4J
  • JBoss 3 (see also CodeZoo: JBoss)
  • WebSphere

Dmitri Maximovich is an independent consultant specializing in software design and development.


Return to ONJava.com.

Prev  [1] [2] [3] [4] 

Close    To Top
  • Prev Article-Java:
  • Next Article-Java:
  • Now: Tutorial for Web and Software Design > Java > JavaBeans > Java Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction