Anthony
Anthony

Reputation: 191

Wild fly multiple datasource

I testing migration from JBoss AS 7.0.1 to Wild Fly 8.2.0 final. Reason : a log4j bug causing deadlocks on database; bug solved only in JBoss EAP I cannot use => Then Wild Fly seems a good candidate

I'm using XA data sources with JTA transaction manager

The configuration (standalone.xml)seems the same between JBoss AS 7.x and Wild Fly 8.2.x :

Data source 1

    <datasource jta="true" jndi-name="java:/DS_Habilitation" pool-name="DS_Habilitation" enabled="true" use-java-context="true" use-ccm="true">
                <connection-url>jdbc:sqlserver://localhost:1433;instanceName=*****;databaseName=Habilitations_DV</connection-url>
                <driver>sqlserver</driver>
                <pool>
                    <min-pool-size>10</min-pool-size>
                    <max-pool-size>100</max-pool-size>
                    <prefill>true</prefill>
                    <use-strict-min>false</use-strict-min>
                    <flush-strategy>FailingConnectionOnly</flush-strategy>
                </pool>
                <security>
                    <user-name>*****</user-name>
                    <password>*******</password>
                </security>
            </datasource>    

Data Source 2

        <datasource jta="true" jndi-name="java:/DS_Referentiel" pool-name="DS_Referentiel" enabled="true" use-java-context="true" use-ccm="true">
            <connection-url>jdbc:sqlserver://localhost:1433;instanceName=*****;databaseName=Referentiel_DV</connection-url>
            <driver>sqlserver</driver>
            <pool>
                <min-pool-size>10</min-pool-size>
                <max-pool-size>100</max-pool-size>
                <prefill>true</prefill>
                <use-strict-min>false</use-strict-min>
                <flush-strategy>FailingConnectionOnly</flush-strategy>
            </pool>
            <security>
                <user-name>*****</user-name>
                <password>******</password>
            </security>
        </datasource>

Data Source 3

<datasource jta="true" jndi-name="java:/DS_Sinistre" pool-name="DS_Sinistre" enabled="true" use-java-context="true" use-ccm="true">
                    <connection-url>jdbc:sqlserver://localhost:1433;instanceName=****;databaseName=Sinistres_DV</connection-url>
                    <driver>sqlserver</driver>
                    <pool>
                        <min-pool-size>10</min-pool-size>
                        <max-pool-size>100</max-pool-size>
                        <prefill>true</prefill>
                        <use-strict-min>false</use-strict-min>
                        <flush-strategy>FailingConnectionOnly</flush-strategy>
                    </pool>
                    <security>
                        <user-name>******</user-name>
                        <password>******</password>
                    </security>
                </datasource>

I start Wild Fly and deploy my WAR correctly When I login I call 2 datasources and I have the error :

ARJUNA012140: Adding multiple last resources is disallowed. Trying to add LastResourceRecord(XAOnePhaseResource

I solved this by adding in the "Wild Fly" server conf file standalone.xml:

   <system-properties>
      <property name="com.arjuna.ats.arjuna.allowMultipleLastResources" value="true"/>
   </system-properties>

Then I have warning indicating me transaction are unsafe because I've multiple datasources

WARN  [com.arjuna.ats.arjuna] (default task-27) ARJUNA012141: Multiple last resources have been added to the current transaction. This is transactionally unsafe and should not be relied upon. Current resource is LastResourceRecord(XAOnePhaseResource(

For information my services are like this (1 transation)

@Service("gestionnaireService") @Transactional(value="transactionManager")

    public class GestionnaireServiceImpl implements GestionnaireService {

        @Autowired
        private UtilisateurService utilisateurService;

        @Autowired
        private GestionnaireDao gestionnaireDao;
    .....
    }

Data source are like :

<bean id="dataSourceReferentiel" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:/DS_Referentiel" />
    </bean>
...
<bean id="sessionFactoryReferentiel" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSourceReferentiel" />
        <property name="mappingResources">
            <list>
                <value>hibernate/referentiel/DonneeReference.hbm.xml</value>
                <value>hibernate/referentiel/LibelleReference.hbm.xml</value>
                <value>hibernate/referentiel/Localite.hbm.xml</value>
                <value>hibernate/referentiel/Banque.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
                <prop key="hibernate.generate_statistics">false</prop>
                <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</prop>
                <prop key="hibernate.show_sql">false</prop>
                <!-- <prop key="transaction.flush_before_completion">true</prop>-->
                <prop key="hibernate.cache.use_query_cache">true</prop>
                <!-- Level 2 cache -->
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <prop key="hibernate.cache.region.factory_class" >org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop>
            </props>
        </property>
    </bean>
...
<!-- Transaction manager -->
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>

Can you give me you opinion on this ?

Thanks

Upvotes: 3

Views: 8845

Answers (1)

Anthony
Anthony

Reputation: 191

ok, thanks for you comments. I managed to avoid warning by setting separated transactions on services using not the same data source

@Service @Transactional(value="transactionManager", propagation=Propagation.REQUIRES_NEW)
public class ReferenceServiceImpl implements ReferenceService {

    @Autowired
    private ReferenceDao dao;
...
}

I've tested that if it fails during the process, all transactions are rollbacked : fine

My last reflexion is do I really need to set XA datasource. My schemas are separated by I use same database instance. Don't know if one day we'll set shemas on different machines.

Anyways I would like to thanks this community for the help provided.

Upvotes: 1

Related Questions