Postgress XA, spring 4, eclipselink

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Postgress XA, spring 4, eclipselink

adrhc
This post was updated on .
Hi, I have a war application deployed on jetty 9.2.1.v20140609 and using bitronix 3.0.0-SNAPSHOT, spring 4, eclipselink 2.5.2 (with static waving) and Postgress XA driver 9.2-1002-jdbc4. AppConfigCtrl.dummyUpdate calls appConfigService.dummyUpdate and I get the exception bitronix-error-on-update.txt. Also when starting jetty shows this really strange log involving jpa & xa (I think is the key to solve this problem): jetty-start-log.txt.

What's the problem ?
Somewhat related to http://bitronix-transaction-manager.10986.n7.nabble.com/Error-enlisting-a-ConnectionJavaProxy-tp1421.html
More related to http://bitronix-transaction-manager.10986.n7.nabble.com/Cannot-be-used-outside-XA-transaction-scope-tp1178.html
Same project & configuration (but without bitronix) runs fine when using xa on jboss-eap-6.2.

@Controller
@RequestMapping("/sys/appconfig")
public class AppConfigCtrl {
        @Autowired
        private AppConfigService appConfigService;
        @Autowired
        private AppConfigRepository appConfigRepository;
        @RequestMapping(value = "/update", produces = "application/json;charset=UTF-8")
        @ResponseBody
        public AppConfig dummyUpdate() {
                logger.debug("BEGIN dummyUpdate");
                appConfigService.dummyUpdate();
                logger.debug("END dummyUpdate");
                return appConfigRepository.findByName("dummy name");
        }

@Service
public class AppConfigService {
        @Transactional
        public void dummyUpdate() {
                AppConfig appConfig = entityManager.find(AppConfig.class, 1);
                appConfig.setValue(String.valueOf(System.currentTimeMillis()));
        }

@Repository
public interface AppConfigRepository extends CrudRepository<AppConfig, Integer> {
        @Override
        public List<AppConfig> findAll();

        AppConfig findByName(String name);
}

The console with jetty shows:
17 Jul 18:27 [DEBUG] [misc.AppConfigCtrl.dummyUpdate] BEGIN dummyUpdate
17 Jul 18:27 [DEBUG] [config.AppConfigService.dummyUpdate_aroundBody0] AppConfig{id=1, name='dummy name', value='1405610833991'}
17 Jul 18:27 [DEBUG] [misc.AppConfigCtrl.dummyUpdate] END dummyUpdate
[EL Fine]: sql: 2014-07-17 18:27:13.997--ServerSession(1901269221)--Connection(1190402820)--Thread(Thread[qtp1507046534-68 - /stoservices/sys/appconfig/up
date,5,main])--SELECT ID, NAME, VALUE FROM APP_CONFIG WHERE (NAME = ?)
        bind => [dummy name]
[EL Fine]: sql: 2014-07-17 18:27:13.999--ServerSession(1901269221)--Thread(Thread[qtp1507046534-68 - /stoservices/sys/appconfig/update,5,main])--SELECT 1
[EL Info]: 2014-07-17 18:27:14.001--UnitOfWork(1142540288)--Thread(Thread[qtp1507046534-68 - /stoservices/sys/appconfig/update,5,main])--Communication fai
lure detected when attempting to perform read query outside of a transaction. Attempting to retry query. Error was: Exception [EclipseLink-4002] (Eclipse
Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: error enlisting a ConnectionJavaProxy of a JdbcPooledConnection from datasource sto-xa in state ACCESSIBLE with
 usage count 1 wrapping org.postgresql.xa.PGXAConnection@54b3dde1 on Pooled connection wrapping physical connection org.postgresql.jdbc4.Jdbc4Connection@3
8201b4
Error Code: 0
Call: SELECT ID, NAME, VALUE FROM APP_CONFIG WHERE (NAME = ?)
        bind => [dummy name]
Query: ReadAllQuery(referenceClass=AppConfig sql="SELECT ID, NAME, VALUE FROM APP_CONFIG WHERE (NAME = ?)").
[EL Fine]: sql: 2014-07-17 18:27:14.005--ServerSession(1901269221)--Connection(2023332589)--Thread(Thread[qtp1507046534-68 - /stoservices/sys/appconfig/up
date,5,main])--SELECT ID, NAME, VALUE FROM APP_CONFIG WHERE (NAME = ?)
        bind => [dummy name]
[EL Fine]: sql: 2014-07-17 18:27:14.007--ServerSession(1901269221)--Thread(Thread[qtp1507046534-68 - /stoservices/sys/appconfig/update,5,main])--SELECT 1
[EL Info]: 2014-07-17 18:27:14.01--UnitOfWork(1142540288)--Thread(Thread[qtp1507046534-68 - /stoservices/sys/appconfig/update,5,main])--Communication fail
ure detected when attempting to perform read query outside of a transaction. Attempting to retry query. Error was: Exception [EclipseLink-4002] (Eclipse P
ersistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: error enlisting a ConnectionJavaProxy of a JdbcPooledConnection from datasource sto-xa in state ACCESSIBLE with
 usage count 1 wrapping org.postgresql.xa.PGXAConnection@54b3dde1 on Pooled connection wrapping physical connection org.postgresql.jdbc4.Jdbc4Connection@3
8201b4
Error Code: 0
Call: SELECT ID, NAME, VALUE FROM APP_CONFIG WHERE (NAME = ?)
        bind => [dummy name]
Query: ReadAllQuery(referenceClass=AppConfig sql="SELECT ID, NAME, VALUE FROM APP_CONFIG WHERE (NAME = ?)").
[EL Fine]: sql: 2014-07-17 18:27:19.014--ServerSession(1901269221)--Connection(718195763)--Thread(Thread[qtp1507046534-68 - /stoservices/sys/appconfig/upd
ate,5,main])--SELECT ID, NAME, VALUE FROM APP_CONFIG WHERE (NAME = ?)
        bind => [dummy name]
[EL Fine]: sql: 2014-07-17 18:27:21.192--ServerSession(1901269221)--Thread(Thread[qtp1507046534-68 - /stoservices/sys/appconfig/update,5,main])--SELECT 1
[EL Info]: 2014-07-17 18:27:21.194--UnitOfWork(1142540288)--Thread(Thread[qtp1507046534-68 - /stoservices/sys/appconfig/update,5,main])--Communication fai
lure detected when attempting to perform read query outside of a transaction. Attempting to retry query. Error was: Exception [EclipseLink-4002] (Eclipse
Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: error enlisting a ConnectionJavaProxy of a JdbcPooledConnection from datasource sto-xa in state ACCESSIBLE with
 usage count 1 wrapping org.postgresql.xa.PGXAConnection@54b3dde1 on Pooled connection wrapping physical connection org.postgresql.jdbc4.Jdbc4Connection@3
8201b4
Error Code: 0
Call: SELECT ID, NAME, VALUE FROM APP_CONFIG WHERE (NAME = ?)
        bind => [dummy name]
Query: ReadAllQuery(referenceClass=AppConfig sql="SELECT ID, NAME, VALUE FROM APP_CONFIG WHERE (NAME = ?)").
...



Spring configuration:


<bean id="btmConfig" factory-method="getConfiguration" class="bitronix.tm.TransactionManagerServices">
        <property name="serverId" value="spring-btm"/>
</bean>

<bean id="userTransaction" factory-method="getTransactionManager"
          class="bitronix.tm.TransactionManagerServices" depends-on="btmConfig" destroy-method="shutdown"/>

<bean id="transactionManager" depends-on="userTransaction"
          class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionManager" ref="userTransaction"/>
        <property name="userTransaction" ref="userTransaction"/>
</bean>

<bean id="dataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource"
          init-method="init" destroy-method="close">
        <property name="className" value="${xa.className}"/>
        <property name="useTmJoin" value="true"/>
        <property name="shareTransactionConnections" value="false"/>
        <property name="allowLocalTransactions" value="false"/>
        <property name="uniqueName" value="${uniqueName}"/>
        <property name="minPoolSize" value="${minPoolSize}"/>
        <property name="maxPoolSize" value="${maxPoolSize}"/>
        <property name="driverProperties">
                <util:properties>
                        <prop key="user">${db.username}</prop>
                        <prop key="password">${password}</prop>
                        <prop key="databaseName">${databaseName}</prop>
                        <prop key="serverName">${serverName}</prop>
                </util:properties>
        </property>
</bean>

<tx:annotation-driven mode="aspectj"/>

<jpa:repositories base-package="ro.uti.sags.stoservices"
                                  entity-manager-factory-ref="entityManager"
                                  transaction-manager-ref="transactionManager">
        <repository:include-filter type="annotation"
                                                           expression="org.springframework.stereotype.Repository"/>
</jpa:repositories>

<bean id="jpaVendorAdapter"
          class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
        <property name="database" value="POSTGRESQL"/>
        <property name="showSql" value="true"/>
        <property name="generateDdl" value="false"/>
        <property name="databasePlatform"
                          value="org.eclipse.persistence.platform.database.PostgreSQLPlatform"/>
</bean>

<util:properties id="jpaPropertyMap">
        <prop key="eclipselink.weaving">static</prop>
        <prop key="eclipselink.target-database">
                org.eclipse.persistence.platform.database.PostgreSQLPlatform
        </prop>
        <prop key="eclipselink.ddl-generation">create-or-extend-tables</prop>
        <prop key="eclipselink.ddl-generation.output-mode">database</prop>
</util:properties>

<bean id="entityManager" depends-on="dataSource"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
       
        <property name="jtaDataSource" ref="dataSource"/>
        <property name="packagesToScan" value="ro.uti.sags.stoservices.persistence"/>
        <property name="persistenceUnitName" value="sto"/>
        <property name="persistenceProvider">
                <bean class="org.eclipse.persistence.jpa.PersistenceProvider"/>
        </property>
        <property name="jpaPropertyMap" ref="jpaPropertyMap"/>
        <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
        <property name="jpaDialect">
                <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect"/>
        </property>
       
</bean>
Loading...