Results 1 to 2 of 2

Thread: JTA propagation - XA datasources in glassfish 3 - not behaving

  1. #1
    Join Date
    May 2009
    Location
    auchenflower
    Posts
    11

    Default JTA propagation - XA datasources in glassfish 3 - not behaving

    Hi all

    I've got a set up that is using JPA persistence.xml with JTA transactions from Glassfish 3. There are a number of XA datasources running with the Oracle ojdbc6 XA Datasource.

    The problem is that it seems to me after two days of exploration is that Transactions appear to be almost always set (or behaves as if set) to REQUIRES_NEW - even if across the same datasource (!).

    configuration is as follows;
    Code:
    <tx:annotation-driven />
    <tx:jta-transaction-manager/>
    <bean id="dao" class="myDaoImpl"/>
    <bean id="service" class="mySvc">
        <property name="dao" ref="dao" />
    </bean>
    "myDaoImpl" has an entity manager;

    Code:
    @PersistenceContext(unitName = "twoPU")
    private EntityManager entityManager;
    and a method;

    Code:
    @Transactional(propagation=Propagation.REQUIRED)
        public List<Item> getDataAndMarkAsDone(String arg1, String ar2, String arg3) {
        // query items
        // now mark them as "done".
        // return them
    }
    "mySvc" has a method;

    Code:
    @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly=false)
     public Result handle(RequestObject inMessage) {
      List<Item> = dao.getDataAndMarkAsDone(string1, string2, string3);
      // now do something else with the items, which doesn't involve a db
      // OH NO!!! throws RuntimeException("not at all good");
    }
    I would have expected that the 'myDao' method is enrolled in the transaction from 'mySvc'. 'mySvc' in this case has no Entity Manager (not that this makes any difference if I add one).

    The problem seems to be that also "mySvc" throws a Runtime exception, the Transaction in "myDao" is not enrolled in it, and commits its changes.

    In fact if I change the "Transactional(propagation=Propagation.REQUIRE D)" on the "myDao" method to "Transactional(propagation=Propagation.MANDATO RY)" then I get exceptions complaining that there's no available transaction.

    However, if I call from one method in "myDao" to another method in "myDao" which is marked Propagation.MANDATORY the transaction propagates.

    Its like every call to a each new spring bean is like it is REQUIRES_NEW (i.e. REQUIRED results in a new transaction) or it doesn't work -- even when the two Spring beans are defined to use the same PersistentContext unitName (it's actually lucky the case is that I need the two different persistence units to actaully be in different transactions!). It seems to me that my JTA transaction manager, or my XA driver configuration is stuffed up. I found some mention of an Oracle XA driver property called "nativeXA" which Glassfish 2.x sets to "false" by default which I manually added to be "true" (in a couple of different variations because it seems to be unclear to me the exact name of this property) but it doesn't seem to make any difference.

    It's spent three days now driving me barmy. Anyone got any ideas or experience with this configuration?

    oh my Spring persistenceUnits config

    Code:
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">
        <property name="persistenceUnits">
          <map>
            <entry key="onePU" value="persistence/onePU" />
            <entry key="twoPU" value="persistence/twoPU" />
          </map>
        </property>
      </bean>
    and my actual persistence.xml:

    Code:
    <persistence 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_2_0.xsd" version="2.0">
    
      <persistence-unit name="onePU" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>jdbc/one</jta-data-source>
     ... classes ...    
    <exclude-unlisted-classes />
        <properties>
          <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
          <property name="hibernate.default_schema " value="one" />
          <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup" />
        </properties>
      </persistence-unit>
    
      <persistence-unit name="twoPU" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>jdbc/two</jta-data-source>
        ... classes ....
        <exclude-unlisted-classes />
        <properties>
          <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
          <property name="hibernate.default_schema " value="two" />
          <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup" />
        </properties>
      </persistence-unit>
    </persistence>
    thanks
    scot.

  2. #2
    Join Date
    Jun 2011
    Posts
    1

    Default

    Hi Scot,
    Were you able to resolve your issue?
    I think I'm noticing much the same behavior.
    Thanks in advance for your feedback

Posting Permissions

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