This discussion is archived
2 Replies Latest reply: May 16, 2013 1:19 AM by 1007201 RSS

doubts on nonxa oracle datasources in Weblogic JTA transaction

1007201 Newbie
Currently Being Moderated
I am doing some studying on XA transaction handling in weblogic 10.3.6. I read a lot materials on web saying that can't enlist more than 1 non xa datasources inside one single XA transaction, so I am doing a simple test: trying to update one record in one oracle database, and inserting one record in another.

The test code is below:

@Stateless(mappedName = "nativeQueryTest")
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class DaoEjb implements .... {

     @PersistenceContext(unitName="nonxa.unit")
     private EntityManager nonXAPC;
     
     @PersistenceContext(unitName="another.nonxa.unit")
     private EntityManager anotherNonXAPC;

     @Override
     public void doUpdateWithNonXaDss() {
          Employee l_entity = nonXAPC.find(Employee.class, "tom");
          l_entity.setAge(new Random().nextInt());
          
          Department l_dep = new Department();
          l_dep.setName("dept" + new Random().nextInt());
          l_dep.setEmployeeNum(new Random().nextInt());
          
          anotherNonXAPC.persist(l_dep);
     }

}

The persistence unit definitions are:
     <persistence-unit name="nonxa.unit" transaction-type="JTA">
          <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
          <jta-data-source>nonxa.ds</jta-data-source>
          <class>entity.Employee</class>
          <exclude-unlisted-classes>true</exclude-unlisted-classes>
          <properties>
               <property name="eclipselink.target-database" value="Oracle" />
<property name="eclipselink.jdbc.batch-writing" value="Oracle-JDBC" />
<property name="eclipselink.target-server" value="WebLogic_10" />

               <property name="eclipselink.logging.parameters" value="true" />
               <property name="eclipselink.logging.logger" value="ServerLogger" />
          </properties>
     </persistence-unit>
     <persistence-unit name="another.nonxa.unit" transaction-type="JTA">
          <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
          <jta-data-source>another.nonxa.ds</jta-data-source>
          <class>entity.Department</class>
          <exclude-unlisted-classes>true</exclude-unlisted-classes>
          <properties>
               <property name="eclipselink.target-database" value="Oracle" />
               <property name="eclipselink.jdbc.batch-writing" value="Oracle-JDBC" />
               <property name="eclipselink.target-server" value="WebLogic_10" />

               <property name="eclipselink.logging.parameters" value="true" />
               <property name="eclipselink.logging.logger" value="ServerLogger" />
          </properties>
     </persistence-unit>

For the two data sources, they are pointed to two different oracle databases on two different physical servers. I use "oracle.jdbc.OracleDriver" as the drivers, and also make sure that "Support Global Transaction" options un-selected.

I used a simple client to invoke the EJB, and saw the method completes without any error: the first record is updated and second record is inserted! Therefore I am really confused:
1) is the JTA transaction XA or not in my small EJB?
2) if it's XA, why can I use two non-XA datasources inside this XA transaction?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points