Announcement Announcement Module
Collapse
No announcement yet.
JTA Transaction Behavior between the container and Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JTA Transaction Behavior between the container and Spring

    I'm running within GlassFish 3.0.1 and I have an EJB that is also a WebService. The class is annotated to allow for a Container transaction to begin on method invocation.

    Code:
    @Stateless
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    @Interceptors(SpringBeanAutowiringInterceptor.class)
    @WebService(...)
    @Service)
    My EJB calls into several Spring Dao class that are using the JPATemplate. The EntityManagerFactory is being injected into my Dao classes with the following annotation:
    Code:
        @PersistenceUnit
        public void setEntityManager(EntityManagerFactory entityManagerFactory) {
            jpaTemplate = new JpaTemplate(entityManagerFactory);
        }
    and configuration:
    Code:
        <jee:jndi-lookup id="entityManagerFactory" jndi-name="persistence/my-pu"/>
    And my persistence.xml is as follows:
    Code:
      <persistence-unit name="my-pu" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    I can see the Transaction being started by the container before method invocation on my EJB and I can see Spring recognizing that there is an existing transaction when it acquires a transaction on method invocation of my dao classes. The problem is that it appears that work in my EntityManager is not transacted. When I read an object from the EntityManager, based upon an ID, a second read will return a different instance of the object. While the data is the same within the instances the objects are not the same.

    When an exception is thrown as a result of an insert operation I can see the transaction marked for rollback and it is rolled back, but the data is not. All inserts that occurred prior to the exception are committed.

    Can the JTATransactionManager participate in a running container managed transaction that is begun on an EJB method invocation?
Working...
X