2 Replies Latest reply on Apr 9, 2018 2:27 AM by mauriclaudio

    Using Narayana with Hibernate + Spring Boot

    mauriclaudio

      As you know, Spring Boot allows programmers to use Narayana, as well as other JTA implementatios (namely Atomikos and Bitronix), out of the box, by simply importing a starter dependency in your POM file and letting Spring Boot do the work for you.

      As far as I understood, to use XA transactions you need to "wrap" your XADatasource in an helper class that is able to enlist a resource within an active transaction. For example, using Atomikos as JTA  manager implementation I need to instantiate a datasource this way

      (i'm using MySQL as database server but that's not relevant):

       

      public DataSource datasource(String dataSourceID, String url, String user, String pwd) {
           MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
           mysqlXaDataSource.setUrl(url);
           mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
           mysqlXaDataSource.setPassword(pwd);
           mysqlXaDataSource.setUser(user);
      
           AtomikosDataSourceBean wrapper = new AtomikosDataSourceBean();
           wrapper.setUniqueResourceName(uniqueXAName);
           wrapper.setMaxPoolSize(MAX_POOL);
           wrapper.setMinPoolSize(MIN_POOL);
           wrapper.setXaDataSource(ds); 
           return wrapper;
      }

       

      Using Bitronix you have to use org.springframework.boot.jta.bitronix.PoolingDataSourceBean class instead of org.springframework.boot.jta.atomikos.AtomikosDataSourceBean, but class usage apart, you configure your wrapper the very same way, providing an unique id, setting pool size and so on.

       

      With Narayama you have to use org.springframework.boot.jta.narayana.NarayanaDataSourceBean class, but it seems that with this wrapper you cannot set an unique id for your resource, nor set pool size in any way.

      I wonder , first of all, if my assumption to use a "transaction manager aware" wrapper for any active datasource is or is not correct, and, in the case it's correct to use a wrapper, how to set pool size properly (or other properties, for example resource ID).

       

      Can anyone help me ?

      TIA