Atomikos Forum |
|
I am fairly new to working with JDBC, XA, and Atomikos\. This is an odd issue that I can't seem to make sense of.
My current test code is like this: Create AtomikosDataSourceBean() and give it parameters. Open a new UserTransactionManager(); Get 3 connections For each connection, get a statement object and use execute(insert blah into blah), with the last connection using a nonexistent table and thus failing. Now, I try to commit the transaction. I expect a failure. The problem is that if I insert a wait time of ten seconds right after I do ut.begin, the transaction will fail as expected, nothing is comitted. If I do not add that wait time, and simply run the code, the behavior is unpredictable. Sometimes it will commit the successful transactions anyways, other times the first two statements (which should insert correctly) will fail. Only if I add that wait time, after ut.begin, does everything go exactly as expected. Do you know what could be causing this behaviour? Do I need to initialize the DataSource bean in some way? Or wait for the UserTransactionManager to perform some function?
My code is nearly identical to the format here:
http://www.atomikos.com/Documentation/ConfiguringJdbc My first thought was that perhaps UserTransactionManager needs time to setup after executing "begin()" before connections acquired through the datasource are XAConnections. I might be completely wrong about this...
I think the transaction is just timing out. I don't think it ever worked as I would expect it to. Perhaps it is an error with how I'm using it:
Perhaps it would be better if I just posted a code snippet: AtomikosDataSourceBean ds = new AtomikosDataSourceBean(); ds.setUniqueResourceName("oracle"); ds.setXaDataSourceClassName("oracle.jdbc.xa.client.OracleXADataSource"); Properties p = new Properties(); p.setProperty("user", "etc"); p.setProperty("password", "etc"); p.setProperty("URL", "jdbc:oracle:thin:etc"); ds.setXaProperties(p); ds.setPoolSize(x); UserTransaction ut = new UserTransactionManager(); ut.begin(); Connection c = ds.getConnection(); Statement c_sta = c.createStatement(); c_sta.execute("insert into etc"); Statement c_sta = c.createStatement(); c_sta.execute("insert into etc"); Statement c_sta = c.createStatement(); //A bad statement, expected to fail c_sta.execute("insert into etc "); } catch (SQLException e2) { System.out.println("An SQL statement failed: " + statement); } c.close(); try { ut.commit(); } catch (Exception re) { System.out.println("ERROR: Could not commit transaction"); } I am expecting an error. The SQL fails, but the others are still committed. |