Hi Vamsi,
Vamsi Atluri wrote:
Hello all,
I am having problem with getting my transactions rolled back. I have read
the documentation a bit about OTM but I am not clear about what I should
do in my situation.
I am using OJB1.0.1 for DB2 and running on WAS 5.0 (currently testing on
WSAD 5.1.2). My data save code looks something like this:
You have two possibilities:
1. Using OJB in non-managed environments (without delegating transaction
handling to JTA - provided by WSAD). Use of the default
PersistenceBrokerFactoryClass (OJB.properties).
2. In managed environments by synchronize OJB within JTA-transactions.
Use of a specific PersistenceBrokerFactoryClass (see OJB.properties and
http://db.apache.org/ojb/docu/guides/deployment.html#Deployment+in+managed+environment+%28e.g.+EJB+based%29).
PersistenceBroker broker =
PersistenceBrokerFactory.defaultPersistenceBroker();
try {
broker.beginTransaction();
broker.store(objA); //step 1
broker.store(objB); //step 2
broker.store(objC); //step 3
broker.deleteByQuery(someQuery); //step 4
broker.store(objD); //step 5
broker.commitTransaction();
} catch(PersistenceBrokerException pbe) {
if(null != broker) {
broker.abortTransaction();
}
} catch(Exception e) {
if(null != broker) {
broker.abortTransaction();
}
} finally {
if(null != broker) {
broker.close();
}
}
It so happens that if there is any Exception during any of the steps, the
previous steps are not being rolled back. Is it possible that I can get
the ConnectionManager from the broker and use it for managing my
transactions? The document says that OJB provides only DB level
transactions but not object level transactions. What does that this
exactly mean?
The PB-api (currently) only offer "DB level transactions"
http://db.apache.org/ojb/docu/guides/pb-guide.html#Transactions
This mean that the PB-api does not use a "unit-of work" concept when
starting a tx. All object manipulation is immediately written to the DB
and rollback when commit fail.
The ODMG-api use a kind of "unit-of-work" and write all modified objects
to DB as recently as tx.commit is called.
Do I "have" to implement OTM (which would be a huge
undertaking given the amount of tables we store)?
no
Your first example will work with the default settings shipped with OJB.
Assume you are using wrong configuration settings. Could you post
OJB.properties and jdbc-connection-descriptor settings?
You have to take care when using
> broker.deleteByQuery(someQuery); //step 4
because this call does bypass cache synchronization.
http://db.apache.org/ojb/api/org/apache/ojb/broker/PersistenceBroker.html#deleteByQuery(org.apache.ojb.broker.query.Query)
regards,
Armin
Or can I do something
like this:
PersistenceBroker broker =
PersistenceBrokerFactory.defaultPersistenceBroker();
java.sql.Connection conn = null;
try {
ConnectionManagerIF connectionManager =
broker.serviceConnectionManager();
conn = connectionManager.getConnection();
conn.setAutoCommit(false);
broker.store(objA); //step 1
broker.store(objB); //step 2
broker.store(objC); //step 3
broker.deleteByQuery(someQuery); //step 4
broker.store(objD); //step 5
conn.commit();
} catch(PersistenceBrokerException pbe) {
if(null != conn) {
conn.rollback();
}
} catch(Exception e) {
if(null != conn) {
conn.rollback();
}
} finally {
if(null != broker) {
broker.close();
}
}
Any help is greatly appreciated in this matter. Thank you.
Regards,
-Vamsi
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]