Announcement Announcement Module
Collapse
No announcement yet.
JtaTransctionManager participating in container Transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JtaTransctionManager participating in container Transaction

    I'm using Spring 3.0 with GlassFish 3.0.1. I've got a WebService defined as an EJB and is defined as requiring a Transaction:
    Code:
    @Stateless
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    @Interceptors(SpringBeanAutowiringInterceptor.class)
    @WebService(...)
    @Service
    The WebService class utilizes my dao framework that is using the Spring JpaTemplate. Each Dao is defined as requiring a Transaction using Spring annotations:
    Code:
    @Transactional(propagation = Propagation.REQUIRED)
    I have defined in my applicationContext.xml the following so Spring's transaction management will work:
    Code:
        <tx:jta-transaction-manager />
    
        <tx:annotation-driven/>
    So my question is, if the GlassFish container begins a global transaction when the WebService is invoked, when a Dao is accessed will Spring's transaction management recognize the existing global transaction and participate in it or will it begin another transaction?

    Thanks...

  • #2
    I think Spring will support the transaction started by your GlassFish. only thing is you should have Spring managed beans means injected/maintained by Spring IoC.

    In my application similar case (except then webservices), EJB+Spring+WebLogic. and all Global transactions managed by WebLogic and its working fine.

    Comment


    • #3
      That's how I had it. All my Dao classes were annotated with @Repository and @Transactional. My service classes, those that contained the Dao references were all annotated the same way, @Service and @Transaction. The Web Service/EJB class, was annotated as listed above:

      Code:
      @Stateless
      @TransactionAttribute(TransactionAttributeType.REQUIRED)
      @Interceptors(SpringBeanAutowiringInterceptor.class)
      @WebService(...)
      @Service
      The @Interceptors annotation allows the container to pass the bean down to Spring for further initialization and everything seemed to work correctly. The trace in the log file showed the container starting the transaction, txId=4, and the Spring trace showed that it was using the same transaction. But it appeared that Spring would perform a transaction synchronization after it returned from my service class, which would seem to cause a commit to occur in the database. Even if an exception was thrown later in the web service method, which showed that the container rolled back the transaction, the work that was performed in the service class, that was managed by Spring, was committed.

      Comment


      • #4
        It seems that GlassFish starts Global Transaction and same getting used by Spring. but i assume that the method which is marked as Propogation Required,, finishes without exception and that's why Spring commits the changes.

        As exception getting thrown at Web Service level which is not managed by Spring so Spring can not do rollback for the same.

        1) you may need to manage Web Service class through Spring, and need to inject service class bean into it - not sure, as i dont have exp. on web services.
        OR
        2) Manage your web service through EJB, get Service class bean from applicationContext.xml, and inject DAO bean to service bean; you can catch any exception in your web service class and do Rollback using EJB.

        Best Luck,,,,
        Last edited by ronak; Jul 16th, 2010, 02:26 AM.

        Comment

        Working...
        X