Problem with Atomikos + XADisk + postgreSQL

382 views
Skip to first unread message

Hermann

unread,
Aug 11, 2011, 9:56:41 PM8/11/11
to XADisk
Hello all,
in a J2SE environment I use the following startup sequence:

UserTransactionServiceFactory utsFactory = new
UserTransactionServiceFactory();
uts = utsFactory.getUserTransactionService(tsProperties);
uts.init(tsProperties);

dbDataSource = dbConfig.createDataSource();
LOG.info("registering JDBC-Resource");
JdbcTransactionalResource jdbcResource = new
JdbcTransactionalResource(
"de.hermannmatthes.workbench.dbDataSource", dbDataSource);
uts.registerResource(jdbcResource);

xaFileSystem =
XAFileSystemProxy.bootNativeXAFileSystem(createXaConfig());
xaFileSystem.waitForBootup(10000L);
LOG.info("Booting completed for the XADisk instance.");
LOG.info("registering XADisk-Resource");
mcf = new XADiskManagedConnectionFactory();
mcf.setInstanceId(fsConfig.getFsInstanceName());
JcaTransactionalResource xaResource = new
JcaTransactionalResource(fsConfig.getFsInstanceName(), mcf);
uts.registerResource(xaResource);

LOG.info("Atomikos startup successfully completed!");

The code runs without visible errors but when I afterwards try to use
XADiskManagedConnection
connection=mcf.createManagedConnection(null, null);
I get the following error:
NoTransactionAssociatedException: The method that was called can
only be called with a transaction associated, but there is no such
transaction present.

Can anybody tell me which mistake I make?

Any hint is highly appreciated.

Hermann

Nitin Verma

unread,
Aug 12, 2011, 9:39:25 AM8/12/11
to XADisk
Hello Hermann,

I guess registerResource is not sufficient. You would also need to
start transactions and enlist the XAResource objects into the
transactions. Something like this:

Transaction tx = uts.getTransactionManager().getTransaction();
tx.enlistResource(xar);

Please see if that does some help.

Thanks,
Nitin

Hermann

unread,
Aug 12, 2011, 10:53:06 AM8/12/11
to XADisk
Hello Nitrin,
do I have to do this on every new UserTransaction or only once on
startup ? And do I have to delist if on every commit/rollback or only
on shutdown?

Thanks
Hermann

Hermann

unread,
Aug 12, 2011, 11:21:23 AM8/12/11
to XADisk
Hello Nitrin,
if I add the following lines
TransactionManager tm = uts.getTransactionManager();
tm.begin();

Transaction txn = tm.getTransaction();
LOG.info("enlisting XADisk-Resource");
XASession xaSession =
xaFileSystem.createSessionForXATransaction();
XAResource xarXADisk = xaSession.getXAResource();
txn.enlistResource(xarXADisk);
after
uts.registerResource(xaResource);
I get a javax.transaction.SystemException (in txn.enlistResource):
There is no registered resource that can recover the given XAResource
instance.
Either enable automatic resource registration, or register a
corresponding resource.

By the way: I tried it with and without automatic resource
registration.

Thanks
Hermann

On 12 Aug., 15:39, Nitin Verma <emailtonve...@gmail.com> wrote:

Hermann

unread,
Aug 14, 2011, 1:41:18 PM8/14/11
to XADisk
Hurra, it works. And it's relatively simple. For JDBC I use the
AtomikosDataSourceBean and for XADisk I do enlist/delist for myself.

If someone wants me to provide the code, just send an email to time-
keeper at freenet dot de.

Thanks a lot to anybody who supported me.

Nitin Verma

unread,
Aug 20, 2011, 9:12:11 AM8/20/11
to XADisk
Hello,

I will try to give an outline here.

The exact code sequence may differ, but the main point is the
enlistResource method (http://download.oracle.com/javaee/5/api/javax/
transaction/Transaction.html#enlistResource
%28javax.transaction.xa.XAResource%29). This is the method provided by
JTA standard to enlist *any* JTA compliant resource with a JTA
transaction. And this remains true independent of the JTA transaction-
manager implementation, whether it is Atomikos or something else.

The enlistResource method accepts an XAResource object. An XAResource
is provided by the vendor of any resource which claims to support
participation in a JTA transaction.

In case of XADisk, this XAResource can be obtained like this:

________________________________________________________

XAFileSystem xafs = ............;
XASession xaSession = xafs.createSessionForXATransaction();
XAResource xarXADisk = xaSession.getXAResource();
________________________________________________________


Similarly, XAResource can also be obtained from the other resources
which are to participate in the JTA transaction:

________________________________________________________

XAResource xarJDBC = ......;
XAResource xarMQ = ........;
XAResource xarXYZ = ........;
________________________________________________________


The way to start a new JTA transaction and obtaining the JTA's
standard Transaction object (http://download.oracle.com/javaee/5/api/
javax/transaction/Transaction.html) can vary. Here
is one of the ways for Atomikos:

________________________________________________________

TransactionManager tm = new
com.atomikos.icatch.jta.UserTransactionManager();
tm.begin();
Transaction transaction = tm.getTransaction();
________________________________________________________


Now, the XAResource objects need to be enlisted with the JTA
transaction using the standard enlistResource method.

________________________________________________________

transaction .enlistResource(xarXADisk );
transaction .enlistResource(xarJDBC);
transaction .enlistResource(xarMQ);
transaction .enlistResource(xarXYZ);
________________________________________________________


Once enlisted, the application performs operations over these
resources and at the end, commits the JTA transaction.

________________________________________________________

transaction.commit().
________________________________________________________


I hope this gives you a general idea. Please feel free to write to me
if you have any questions.

Cheers,
Nitin
Reply all
Reply to author
Forward
0 new messages