0 Replies Latest reply: Nov 25, 2011 10:38 AM by 802414 RSS

    CMT rollbacks incomplete

    802414
      CMT rollbacks are incomplete when I deploy 2 SLSBs in WLS 10.3.5 configured for the following scenario (full source below):

      1. Remote client calls the following method in first SLSB:
           @TransactionAttribute(TransactionAttributeType.REQUIRED)
           public void startTest() {
                LOG.info("Starting test...");
      
                TestEntity entity = new TestEntity();
                entity.setText("New test entity at: " + System.currentTimeMillis());
                entityManager.persist(entity);
      
                helper.help();
           }
      2. A database integrity constraint violation occurs during EJB local call of the second SLSB (helper.help()):
           @TransactionAttribute(TransactionAttributeType.REQUIRED)
           public void help() {
                LOG.info("Helping...");
      
                TestEntity helperEntity = new TestEntity();
                
                // Comment this line to trigger an integrity constraint violation
      //          helperEntity.setText("New helper entity at: " + System.currentTimeMillis());
                entityManager.persist(helperEntity);
           }
      - Actual result: the TestEntity instance in (1) is committed and the TestEntity insrtance in (2) is rolled back.
      - Expected result: the TestEntity instance in (1) and (2) are both rolled back, because they belong to the same CMT context.

      Do you have any ideas about what could go wrong? Many thanks in advance!!
      h3. Full source
      h4. TestEntity.java
      package txtest;
      
      import java.io.Serializable;
      
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      import javax.persistence.SequenceGenerator;
      import javax.persistence.Table;
      
      @Entity
      @Table(name = "rac_test")
      public class TestEntity implements Serializable {
           
           @Id
           @GeneratedValue(generator = "RacTestSeq")
           @SequenceGenerator(name = "RacTestSeq", sequenceName = "rac_test_seq", allocationSize = 1)
           private long id;
           
           @Column
           private String text;
           
           public void setText(String text) {
                this.text = text;
           }
      }
      h4. TxTestEJB.java
      package txtest;
      
      import java.util.logging.Logger;
      
      import javax.annotation.Resource;
      import javax.ejb.EJB;
      import javax.ejb.SessionContext;
      import javax.ejb.Stateless;
      import javax.ejb.TransactionAttribute;
      import javax.ejb.TransactionAttributeType;
      import javax.ejb.TransactionManagement;
      import javax.ejb.TransactionManagementType;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      @Stateless(mappedName="TxTest")
      @TransactionManagement(TransactionManagementType.CONTAINER)
      public class TxTestEJB implements TxTestRemote {
      
           private static final Logger LOG = Logger.getLogger(TxTestEJB.class.getName());
           
           @PersistenceContext(unitName = "txtest")
           private EntityManager entityManager;
           
           @Resource
           private SessionContext sessionContext;
      
           @EJB
           private TxTestHelperLocal helper;
           
           @TransactionAttribute(TransactionAttributeType.REQUIRED)
           public void startTest() {
                LOG.info("Starting test...");
      
                TestEntity entity = new TestEntity();
                entity.setText("New test entity at: " + System.currentTimeMillis());
                entityManager.persist(entity);
      
                helper.help();
           }
      
      }
      h4. TxTestRemote.java
      package txtest;
      
      import javax.ejb.Remote;
      import javax.ejb.Timer;
      
      @Remote
      public interface TxTestRemote {
           
           public void startTest();
      }
      h4. TxTestHelperEJB.java
      package txtest;
      
      import java.util.logging.Logger;
      
      import javax.ejb.Stateless;
      import javax.ejb.TransactionAttribute;
      import javax.ejb.TransactionAttributeType;
      import javax.ejb.TransactionManagement;
      import javax.ejb.TransactionManagementType;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      @Stateless(mappedName="RacTestHelper")
      @TransactionManagement(TransactionManagementType.CONTAINER)
      public class TxTestHelperEJB implements TxTestHelperLocal {
      
           private static final Logger LOG = Logger.getLogger(TxTestHelperEJB.class.getName());
           
           @PersistenceContext(unitName = "txtest")
           private EntityManager entityManager;
           
           @TransactionAttribute(TransactionAttributeType.REQUIRED)
           public void help() {
                LOG.info("Helping...");
      
                TestEntity helperEntity = new TestEntity();
                
                // Comment this line to trigger an integrity constraint violation
      //          helperEntity.setText("New helper entity at: " + System.currentTimeMillis());
                entityManager.persist(helperEntity);
           }
      }
      h4. TxTestHelperLocal.java
      package txtest;
      
      import javax.ejb.Local;
      
      @Local
      public interface TxTestHelperLocal {
           
           public void help();
      }
      h4. persistence.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence                                  http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
        <persistence-unit name="txtest" transaction-type="JTA">
          <description>The RAC test database</description>
          <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
          <jta-data-source>jdbc/myds</jta-data-source>
          <class>txtest.TestEntity</class>
          <properties>
            <property name="eclipselink.target-database" value="Oracle"/>
            <!-- Level FINE logs SQL statements -->
            <property name="eclipselink.logging.level" value="WARNING"/>
            <property name="eclipselink.target-server" value="WebLogic_10"/>
          </properties>
        </persistence-unit>
      </persistence>
      h4. Oracle Database setup script
      CREATE TABLE rac_test (ID NUMBER(19,0) NOT NULL, text VARCHAR2(255) NOT NULL);
      CREATE SEQUENCE rac_test_seq INCREMENT BY 1 START WITH 100;
      Edited by: Bas Cancrinus on 25-nov-2011 8:38