Transaction Problems
dciarnie Aug 17, 2001 7:55 PMI am having troubles using any transactional attributes other than 'NotSupported' in JBoss.
While doing some rollback testing I noticed that while my first test run would work ok, the second test run would leave rows locked in the DB (SQLServer, in this case).
The beans that I've developed look something like:
public class EJB1 implements EntityBean
{
...
public void ejbRemove()
{
try
{
this.removeRow();
}
catch(SQLException se)
{
this.context.setRollBackOnly();
throw new RemoveException(se.getMessage());
}
catch(Exception e)
{
throw new EJBException(e.getMessage());
}
}
private void removeRow() throws SQLException
{
String sql = "delete from table1 where id = ?";
PreparedStatement stmt = this.dbconn.prepareStatement(sql);
stmt.setString(this.m_Id);
stmt.executeUpdate();
stmt.close();
throw new SQLException("Rollback Test");
}
}
The last line is simply to test that rollback works properly on error.
My test client looks like:
public class TestClient
{
public TestClient()
{
... get Home interface ...
home.remove(id);
}
public static void main(String args[])
{
TestClient test = new TestClient();
}
}
In ejb-jar.xml I have set the transactional attribute to 'Required'.
As stated above. The first run through TestClient works but the second does not.
Using the SQLServer profiler I noticed that on the first run through, a rollback is sent to the DB but not on the second run. This, obviously, is the reason for the row-lock. The transaction has not been rolled back (i.e. its not finished).
I started poking around in the JBoss code and discovered that when org.jboss.tm.TxCapsule.rollbackResources() is called, resourceCount is 1 the first time and 0 on subsequent calls. This explains why the rollback is not being sent. I also discovered org.jboss.tm.TxCapsule.addResource() is only called on the first run and not on the second. I think that explains why resourceCount is 0 on the second run. What I don't know is why addResource() is not called on the second run.
I don't know whether the problem is my implementation/configuration or whether JBoss is the problem. Hopefully someone can shed some light on this problem.
Any help is greatly appreciated.
Thanks in advance,
Dan Ciarniello