Results 1 to 6 of 6

Thread: Spring transactions + CMT

  1. #1
    Join Date
    Nov 2004
    Posts
    12

    Default Spring transactions + CMT

    Hello,

    I have a POJO "handler" which is used basically as a session bean, ie it encapsulates business logic and needs some type of transaction scope for a certain method.

    My question is, can Spring's transcation management join the transactions of CMP beans operations (CMT) inside my handler which executes the business logic.

    For all i know it is not possible to join CMT and JTA java:comp/UserTransaction transactions....

    regards,
    -Kristoffer

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    Take a look at this post on the dev. mailing list.

  3. #3
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    Effectively, joining EJB CMT transactions is hardly ever a problem; for example, synchronizing O/R mapper resources with EJB CMT transactions. In the case of Hibernate, this even works without Spring transaction demarcation: HibernateTemplate will auto-detect the current JTA transaction, as long as a Hibernate TransactionManagerLookup is configured.

    The problems start to arise when you use EJB CMT at the facade level but Spring transaction demarcation for finer-grained components. Joining in via PROPAGATION_REQUIRED is usually not a problem, but suspending transactions via PROPAGATION_REQUIRES_NEW or PROPAGATION_NOT_SUPPORTED might be, as it implies suspending a transaction that has been started by EJB CMT.

    Juergen

  4. #4
    Join Date
    Aug 2004
    Location
    Vancouver, Canada
    Posts
    25

    Default

    Juergen,

    I'm planning to use CMT.

    Is there any way to just use the rollback functionality ( based on Exception) provided by the Spring TransactionProxy (without propagation, isolation level and timeout) in the case of CMT?

    I'm thinking of creating a simple proxy with throws advise that uses configuration with a list of exceptions, Exception1, Exception2 etc..When any of these exceptions are thrown, i want to call "setRollbackOnly" method on the EJB context.

    The issue is the EJB context....Is there any easy way for the proxy to get access to the context ?

    Thanks,
    Ram.

  5. #5
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    You could use a Spring TransactionProxyFactoryBean with PROPAGATION_REQUIRED (or PROPAGATION_MANDATORY to enforce an existing transaction) and JtaTransactionManager as backend: This will always join into existing EJB CMT transactions, marking the EJB transaction rollback-only according to the rollback rules.

    Spring will work with the JTA UserTransaction here, calling setRollbackOnly on it when necessary. While this is not directly covered by the J2EE spec, it works nicely on all known J2EE servers. Essentially, if your server allows JTA UserTransaction access within EJB CMT, then Spring transaction demarcation will work even with EJB transactions.

    If you prefer to use a custom AOP interceptor, I recommend to fetch the JTA UserTransaction from JNDI ("java:comp/UserTransaction") and call setRollbackOnly on it when necessary. Don't bother with getting access to the EJBContext; the UserTransaction will work too on all known J2EE servers, as indicated above.

    Juergen

  6. #6
    Join Date
    Aug 2004
    Location
    Vancouver, Canada
    Posts
    25

    Default

    The EJB spec explicitly mentions (in section 17.3.4)

    The enterprise bean’s business methods, message listener methods, or ejbTimeout method must not
    attempt to obtain or use the javax.transaction.UserTransaction interface.
    Its good to hear that it works with all AppServers....I'm just worried that this may change with the next release of the AppServer (I'm sure Spring will figure out a solution if that happens.. ).

    Thanks for your quick response.

    --Ram.

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Replies: 5
    Last Post: Aug 25th, 2005, 05:37 PM
  3. Replies: 6
    Last Post: May 25th, 2005, 01:56 AM
  4. A Spring Class Loader?
    By azzoti in forum Architecture
    Replies: 8
    Last Post: May 7th, 2005, 04:02 AM
  5. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •