I'm using Castor 0.9.3 in JBoss to provide persistence for my classes, and
using container manager transactions.
The code appeared to be all working fine, until I decided to a transaction
test.
The test basically creates 2 business objects in an ejb method, and then
throws a javax.ejb.EJBException - this should result in the transaction
being rolled back.
I've also tried setting setRollbackOnly() on the context, but in either case
the transaction doesn't roll back, and the objects are committed to the
database.
Here's an example of my code from the ejb:
//Test transaction using castor rollback correctly
public void testTransactions()
{
try
{
Database db = null;
try
{
db = CastorHelper.instance().getDB();
Log.info("autostore is " + db.isAutoStore());
//do something in db
SystemProperty prop = new SystemProperty();
prop.setName("wibble1");
prop.setValue("value");
db.create(prop);
Log.info("Created wibble1");
}
finally
{
if (db != null && !db.isClosed()) db.close();
}
try
{
db = CastorHelper.instance().getDB();
//do something in db
SystemProperty prop = new SystemProperty();
prop.setName("wibble2");
prop.setValue("value");
db.create(prop);
Log.info("Created wibble2");
//Now throw an exception - everything should rollback
throw new RuntimeException("oooooh!! nurse");
}
finally
{
if (db != null && !db.isClosed()) db.close();
}
}
catch(Exception e)
{
Log.error("Caught exception", e);
throw new javax.ejb.EJBException("blah", e);
}
}
The CastorHelper class simply gets the DataObjects class from JNDI and
invokes the getDatabase() method on it.
The deployment descriptor for my ejb specifies container transactions.
I don't think this is a JBoss problem, since everything seems to work ok
with raw JDBC access.
Help!!!!
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev