You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Vamsi Atluri <vk...@yahoo.com> on 2006/02/21 01:43:47 UTC
Help needed for Transaction Rollbacks
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:
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? Do I "have" to implement OTM (which would be a huge
undertaking given the amount of tables we store)? 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: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Help needed for Transaction Rollbacks
Posted by Vamsi Atluri <vk...@yahoo.com>.
Hi Armin,
Again, I am really thankful to you for clearing that up. I followed both
the managed and non-managed approaches and both worked.
For the non-managed scenario, I set the settings as such:
useAutoCommit="2"
PersistenceBrokerFactoryClass=org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl
ConnectionFactoryClass=ConnectionFactoryClass=org.apache.ojb.broker.accesslayer.ConnectionFactoryPooledImpl
And the code looks as follows:
try {
broker.beginTransaction();
broker.store(objA);
broker.store(objB);
broker.deleteByQuery(someQuery);
broker.store(objC);
broker.commitTransaction();
} catch (Exception e) {
broker.abortTransaction();
}
For the managed scneario, I set the settings as such:
useAutoCommit="0"
PersistenceBrokerFactoryClass=org.apache.ojb.broker.core.PersistenceBrokerFactorySyncImpl
ConnectionFactoryClass=org.apache.ojb.broker.accesslayer.ConnectionFactoryManagedImpl
And the code looks as follows(I am using WSAD 5.1.2):
javax.transaction.UserTransaction userTx = null;
try {
InitialContext initCtx = new InitialContext();
userTx = (UserTransaction)initCtx.lookup("java:comp/UserTransaction");
userTx.begin();
broker.store(objA);
broker.store(objB);
broker.deleteByQuery(someQuery);
broker.store(objC);
userTx.commit();
} catch(Exception e) {
userTx.rollback();
}
Both of the above approaches worked. Now I would like to know which of
them is the better approach? What are the pros and cons of managed vs.
non-managed? Is there a document I can refer to?
Again, thank you very much for your help.
Regards,
-Vamsi
--- Armin Waibel <ar...@apache.org> wrote:
> Hi Vamsi,
>
> > Is there something I should change in OJB.properties? I am using
> ojb1.0.1.
>
> Seems you mixed the managed and non-managed settings.
>
> managed:
> useAutoCommit="0"
>
PersistenceBrokerFactoryClass=org.apache.ojb.broker.core.PersistenceBrokerFactorySyncImpl
>
ConnectionFactoryClass=org.apache.ojb.broker.accesslayer.ConnectionFactoryManagedImpl
>
> non-managed:
> useAutoCommit="1" or "2"
>
PersistenceBrokerFactoryClass=org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl
> ConnectionFactoryClass= all except ConnectionFactoryManagedImpl
>
> Your example source seems to expect a non-managed environment, because
> you use the PB-tx demarcation.
> In managed environments you have to use programmatic transactions via
> JTA UserTransaction or declarative transaction e.g. via session beans
> and deployment descriptor entries (PB-tx declaration is not allowed).
>
> regards,
> Armin
>
>
>
> Vamsi Atluri wrote:
> > Hi Armin,
> >
> > I really appreciate your response. The connection descriptor is as
> > follows:
> >
> > <jdbc-connection-descriptor
> > jcd-alias="OJBDb"
> > default-connection="true"
> > platform="Db2"
> > jdbc-level="1.0"
> > jndi-datasource-name="jdbc/ojbDataSource"
> > username="someUserName"
> > password="somePassWord"
> > batch-mode="false"
> > useAutoCommit="0"
> > ignoreAutoCommitExceptions="false">
> > <sequence-manager
> >
>
className="org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl">
> > <attribute attribute-name="grabSize"
> > attribute-value="1"></attribute>
> > </sequence-manager>
> > </jdbc-connection-descriptor>
> >
> > The OJB.properties file has the following settings:
> >
> > # repository file settings
> > repositoryFile=repository.xml
> > useSerializedRepository=false
> > serializedRepositoryPath=.
> >
> > # PersistenceBrokerFactory / PersistenceBroker
> >
>
PersistenceBrokerFactoryClass=org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl
> >
> PersistenceBrokerClass=org.apache.ojb.broker.core.PersistenceBrokerImpl
> >
> > # PersistenceBroker pool
> > maxActive=100
> > maxIdle=-1
> > maxWait=2000
> > timeBetweenEvictionRunsMillis=-1
> > minEvictableIdleTimeMillis=1000000
> > whenExhaustedAction=2
> >
> > # ConnectionFactory / Default ConnectionPool
> >
>
ConnectionFactoryClass=org.apache.ojb.broker.accesslayer.ConnectionFactoryManagedImpl
> >
> > # ConnectionManager
> >
>
ConnectionManagerClass=org.apache.ojb.broker.accesslayer.ConnectionManagerImpl
> >
> > # SqlGenerator
> >
>
SqlGeneratorClass=org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl
> >
> > # IndirectionHandler
> >
>
IndirectionHandlerClass=org.apache.ojb.broker.core.proxy.IndirectionHandlerDefaultImpl
> >
> > # ListProxy
> > ListProxyClass=org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl
> >
> > # SetProxy
> > SetProxyClass=org.apache.ojb.broker.core.proxy.SetProxyDefaultImpl
> >
> > # CollectionProxy
> >
>
CollectionProxyClass=org.apache.ojb.broker.core.proxy.CollectionProxyDefaultImpl
> >
> > # StatementManager
> >
> StatementManagerClass=org.apache.ojb.broker.accesslayer.StatementManager
> >
> > # StatementsForClass
> >
>
StatementsForClassClass=org.apache.ojb.broker.accesslayer.StatementsForClassImpl
> >
> > # JdbcAccess
> > JdbcAccessClass=org.apache.ojb.broker.accesslayer.JdbcAccessImpl
> >
> > # Object cache
> > ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCacheDefaultImpl
> > descriptorBasedCaches=false
> >
> > # Locking
> > LockManagerClass=org.apache.ojb.odmg.locking.LockManagerDefaultImpl
> > LockMapClass=org.apache.ojb.odmg.locking.InMemoryLockMapImpl
> > LockTimeout=60000
> > ImplicitLocking=true
> > LockServletUrl=http://127.0.0.1:8080/ojb-lockserver
> > LockAssociations=WRITE
> >
> > # OQL / SQL settings
> > OqlCollectionClass=org.apache.ojb.odmg.collections.DListImpl_2
> > SqlInLimit=200
> >
> > # ODMG settings
> > ImplementationClass=org.apache.ojb.odmg.ImplementationDefaultImpl
> > OJBTxManagerClass=org.apache.ojb.odmg.LocalTxManager
> > DListClass=org.apache.ojb.odmg.collections.DListImpl_2
> > DArrayClass=org.apache.ojb.odmg.collections.DListImpl_2
> > DMapClass=org.apache.ojb.odmg.collections.DMapImpl
> > DBagClass=org.apache.ojb.odmg.collections.DBagImpl
> > DSetClass=org.apache.ojb.odmg.collections.DSetImpl
> >
> > # Meta data / mapping settings
> >
>
PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessImpl
> >
> > # Transaction Management and assocation
> >
>
JTATransactionManagerClass=org.apache.ojb.broker.transaction.tm.WebSphereTransactionManagerFactory
> >
> > # Logging
> > LoggerClass=org.apache.ojb.broker.util.logging.PoorMansLoggerImpl
> > LoggerConfigFile=log4j.properties
> > DEFAULT.LogLevel=WARN
> > org.apache.ojb.broker.core.PersistenceBrokerImpl.LogLevel=WARN
> >
>
org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.LogLevel=WARN
> > org.apache.ojb.broker.metadata.RepositoryXmlHandler.LogLevel=WARN
> >
>
org.apache.ojb.broker.metadata.ConnectionDescriptorXmlHandler.LogLevel=WARN
> > org.apache.ojb.broker.accesslayer.JdbcAccessImpl.LogLevel=WARN
> > org.apache.ojb.broker.accesslayer.RsIterator.LogLevel=WARN
> > org.apache.ojb.broker.accesslayer.StatementsForClassImpl.LogLevel=WARN
> >
>
org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.LogLevel=WARN
> > org.apache.ojb.broker.metadata.RepositoryPersistor.LogLevel=WARN
> >
>
org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.LogLevel=WARN
> > org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.LogLevel=WARN
> > org.apache.ojb.broker.core.proxy.IndirectionHandler.LogLevel=WARN
> > ODMG.LogLevel=DEBUG
> > JDO.LogLevel=DEBUG
> > performance.LogLevel=INFO
> > soda.LogLevel=WARN
> > ConfigurableFactory.LogLevel=WARN
> >
> > Is there something I should change in OJB.properties? I am using
> ojb1.0.1.
> > Any help is appreciated. Thanks.
> >
> > Regards,
> > -Vamsi
> >
> > --- Armin Waibel <ar...@apache.org> wrote:
> >
> >> 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
>
=== message truncated ===
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Help needed for Transaction Rollbacks
Posted by Armin Waibel <ar...@apache.org>.
Hi Vamsi,
> Is there something I should change in OJB.properties? I am using
ojb1.0.1.
Seems you mixed the managed and non-managed settings.
managed:
useAutoCommit="0"
PersistenceBrokerFactoryClass=org.apache.ojb.broker.core.PersistenceBrokerFactorySyncImpl
ConnectionFactoryClass=org.apache.ojb.broker.accesslayer.ConnectionFactoryManagedImpl
non-managed:
useAutoCommit="1" or "2"
PersistenceBrokerFactoryClass=org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl
ConnectionFactoryClass= all except ConnectionFactoryManagedImpl
Your example source seems to expect a non-managed environment, because
you use the PB-tx demarcation.
In managed environments you have to use programmatic transactions via
JTA UserTransaction or declarative transaction e.g. via session beans
and deployment descriptor entries (PB-tx declaration is not allowed).
regards,
Armin
Vamsi Atluri wrote:
> Hi Armin,
>
> I really appreciate your response. The connection descriptor is as
> follows:
>
> <jdbc-connection-descriptor
> jcd-alias="OJBDb"
> default-connection="true"
> platform="Db2"
> jdbc-level="1.0"
> jndi-datasource-name="jdbc/ojbDataSource"
> username="someUserName"
> password="somePassWord"
> batch-mode="false"
> useAutoCommit="0"
> ignoreAutoCommitExceptions="false">
> <sequence-manager
> className="org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl">
> <attribute attribute-name="grabSize"
> attribute-value="1"></attribute>
> </sequence-manager>
> </jdbc-connection-descriptor>
>
> The OJB.properties file has the following settings:
>
> # repository file settings
> repositoryFile=repository.xml
> useSerializedRepository=false
> serializedRepositoryPath=.
>
> # PersistenceBrokerFactory / PersistenceBroker
> PersistenceBrokerFactoryClass=org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl
> PersistenceBrokerClass=org.apache.ojb.broker.core.PersistenceBrokerImpl
>
> # PersistenceBroker pool
> maxActive=100
> maxIdle=-1
> maxWait=2000
> timeBetweenEvictionRunsMillis=-1
> minEvictableIdleTimeMillis=1000000
> whenExhaustedAction=2
>
> # ConnectionFactory / Default ConnectionPool
> ConnectionFactoryClass=org.apache.ojb.broker.accesslayer.ConnectionFactoryManagedImpl
>
> # ConnectionManager
> ConnectionManagerClass=org.apache.ojb.broker.accesslayer.ConnectionManagerImpl
>
> # SqlGenerator
> SqlGeneratorClass=org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl
>
> # IndirectionHandler
> IndirectionHandlerClass=org.apache.ojb.broker.core.proxy.IndirectionHandlerDefaultImpl
>
> # ListProxy
> ListProxyClass=org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl
>
> # SetProxy
> SetProxyClass=org.apache.ojb.broker.core.proxy.SetProxyDefaultImpl
>
> # CollectionProxy
> CollectionProxyClass=org.apache.ojb.broker.core.proxy.CollectionProxyDefaultImpl
>
> # StatementManager
> StatementManagerClass=org.apache.ojb.broker.accesslayer.StatementManager
>
> # StatementsForClass
> StatementsForClassClass=org.apache.ojb.broker.accesslayer.StatementsForClassImpl
>
> # JdbcAccess
> JdbcAccessClass=org.apache.ojb.broker.accesslayer.JdbcAccessImpl
>
> # Object cache
> ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCacheDefaultImpl
> descriptorBasedCaches=false
>
> # Locking
> LockManagerClass=org.apache.ojb.odmg.locking.LockManagerDefaultImpl
> LockMapClass=org.apache.ojb.odmg.locking.InMemoryLockMapImpl
> LockTimeout=60000
> ImplicitLocking=true
> LockServletUrl=http://127.0.0.1:8080/ojb-lockserver
> LockAssociations=WRITE
>
> # OQL / SQL settings
> OqlCollectionClass=org.apache.ojb.odmg.collections.DListImpl_2
> SqlInLimit=200
>
> # ODMG settings
> ImplementationClass=org.apache.ojb.odmg.ImplementationDefaultImpl
> OJBTxManagerClass=org.apache.ojb.odmg.LocalTxManager
> DListClass=org.apache.ojb.odmg.collections.DListImpl_2
> DArrayClass=org.apache.ojb.odmg.collections.DListImpl_2
> DMapClass=org.apache.ojb.odmg.collections.DMapImpl
> DBagClass=org.apache.ojb.odmg.collections.DBagImpl
> DSetClass=org.apache.ojb.odmg.collections.DSetImpl
>
> # Meta data / mapping settings
> PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessImpl
>
> # Transaction Management and assocation
> JTATransactionManagerClass=org.apache.ojb.broker.transaction.tm.WebSphereTransactionManagerFactory
>
> # Logging
> LoggerClass=org.apache.ojb.broker.util.logging.PoorMansLoggerImpl
> LoggerConfigFile=log4j.properties
> DEFAULT.LogLevel=WARN
> org.apache.ojb.broker.core.PersistenceBrokerImpl.LogLevel=WARN
> org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.LogLevel=WARN
> org.apache.ojb.broker.metadata.RepositoryXmlHandler.LogLevel=WARN
> org.apache.ojb.broker.metadata.ConnectionDescriptorXmlHandler.LogLevel=WARN
> org.apache.ojb.broker.accesslayer.JdbcAccessImpl.LogLevel=WARN
> org.apache.ojb.broker.accesslayer.RsIterator.LogLevel=WARN
> org.apache.ojb.broker.accesslayer.StatementsForClassImpl.LogLevel=WARN
> org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.LogLevel=WARN
> org.apache.ojb.broker.metadata.RepositoryPersistor.LogLevel=WARN
> org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.LogLevel=WARN
> org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.LogLevel=WARN
> org.apache.ojb.broker.core.proxy.IndirectionHandler.LogLevel=WARN
> ODMG.LogLevel=DEBUG
> JDO.LogLevel=DEBUG
> performance.LogLevel=INFO
> soda.LogLevel=WARN
> ConfigurableFactory.LogLevel=WARN
>
> Is there something I should change in OJB.properties? I am using ojb1.0.1.
> Any help is appreciated. Thanks.
>
> Regards,
> -Vamsi
>
> --- Armin Waibel <ar...@apache.org> wrote:
>
>> 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: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Help needed for Transaction Rollbacks
Posted by Vamsi Atluri <vk...@yahoo.com>.
Hi Armin,
I really appreciate your response. The connection descriptor is as
follows:
<jdbc-connection-descriptor
jcd-alias="OJBDb"
default-connection="true"
platform="Db2"
jdbc-level="1.0"
jndi-datasource-name="jdbc/ojbDataSource"
username="someUserName"
password="somePassWord"
batch-mode="false"
useAutoCommit="0"
ignoreAutoCommitExceptions="false">
<sequence-manager
className="org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl">
<attribute attribute-name="grabSize"
attribute-value="1"></attribute>
</sequence-manager>
</jdbc-connection-descriptor>
The OJB.properties file has the following settings:
# repository file settings
repositoryFile=repository.xml
useSerializedRepository=false
serializedRepositoryPath=.
# PersistenceBrokerFactory / PersistenceBroker
PersistenceBrokerFactoryClass=org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl
PersistenceBrokerClass=org.apache.ojb.broker.core.PersistenceBrokerImpl
# PersistenceBroker pool
maxActive=100
maxIdle=-1
maxWait=2000
timeBetweenEvictionRunsMillis=-1
minEvictableIdleTimeMillis=1000000
whenExhaustedAction=2
# ConnectionFactory / Default ConnectionPool
ConnectionFactoryClass=org.apache.ojb.broker.accesslayer.ConnectionFactoryManagedImpl
# ConnectionManager
ConnectionManagerClass=org.apache.ojb.broker.accesslayer.ConnectionManagerImpl
# SqlGenerator
SqlGeneratorClass=org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl
# IndirectionHandler
IndirectionHandlerClass=org.apache.ojb.broker.core.proxy.IndirectionHandlerDefaultImpl
# ListProxy
ListProxyClass=org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl
# SetProxy
SetProxyClass=org.apache.ojb.broker.core.proxy.SetProxyDefaultImpl
# CollectionProxy
CollectionProxyClass=org.apache.ojb.broker.core.proxy.CollectionProxyDefaultImpl
# StatementManager
StatementManagerClass=org.apache.ojb.broker.accesslayer.StatementManager
# StatementsForClass
StatementsForClassClass=org.apache.ojb.broker.accesslayer.StatementsForClassImpl
# JdbcAccess
JdbcAccessClass=org.apache.ojb.broker.accesslayer.JdbcAccessImpl
# Object cache
ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCacheDefaultImpl
descriptorBasedCaches=false
# Locking
LockManagerClass=org.apache.ojb.odmg.locking.LockManagerDefaultImpl
LockMapClass=org.apache.ojb.odmg.locking.InMemoryLockMapImpl
LockTimeout=60000
ImplicitLocking=true
LockServletUrl=http://127.0.0.1:8080/ojb-lockserver
LockAssociations=WRITE
# OQL / SQL settings
OqlCollectionClass=org.apache.ojb.odmg.collections.DListImpl_2
SqlInLimit=200
# ODMG settings
ImplementationClass=org.apache.ojb.odmg.ImplementationDefaultImpl
OJBTxManagerClass=org.apache.ojb.odmg.LocalTxManager
DListClass=org.apache.ojb.odmg.collections.DListImpl_2
DArrayClass=org.apache.ojb.odmg.collections.DListImpl_2
DMapClass=org.apache.ojb.odmg.collections.DMapImpl
DBagClass=org.apache.ojb.odmg.collections.DBagImpl
DSetClass=org.apache.ojb.odmg.collections.DSetImpl
# Meta data / mapping settings
PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessImpl
# Transaction Management and assocation
JTATransactionManagerClass=org.apache.ojb.broker.transaction.tm.WebSphereTransactionManagerFactory
# Logging
LoggerClass=org.apache.ojb.broker.util.logging.PoorMansLoggerImpl
LoggerConfigFile=log4j.properties
DEFAULT.LogLevel=WARN
org.apache.ojb.broker.core.PersistenceBrokerImpl.LogLevel=WARN
org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.LogLevel=WARN
org.apache.ojb.broker.metadata.RepositoryXmlHandler.LogLevel=WARN
org.apache.ojb.broker.metadata.ConnectionDescriptorXmlHandler.LogLevel=WARN
org.apache.ojb.broker.accesslayer.JdbcAccessImpl.LogLevel=WARN
org.apache.ojb.broker.accesslayer.RsIterator.LogLevel=WARN
org.apache.ojb.broker.accesslayer.StatementsForClassImpl.LogLevel=WARN
org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.LogLevel=WARN
org.apache.ojb.broker.metadata.RepositoryPersistor.LogLevel=WARN
org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.LogLevel=WARN
org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.LogLevel=WARN
org.apache.ojb.broker.core.proxy.IndirectionHandler.LogLevel=WARN
ODMG.LogLevel=DEBUG
JDO.LogLevel=DEBUG
performance.LogLevel=INFO
soda.LogLevel=WARN
ConfigurableFactory.LogLevel=WARN
Is there something I should change in OJB.properties? I am using ojb1.0.1.
Any help is appreciated. Thanks.
Regards,
-Vamsi
--- Armin Waibel <ar...@apache.org> wrote:
> 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: ojb-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: ojb-user-help@db.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Help needed for Transaction Rollbacks
Posted by Armin Waibel <ar...@apache.org>.
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: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Help needed for Transaction Rollbacks
Posted by Dennis Bekkering <dj...@gmail.com>.
>
> I think OTM is kind of "deprecated", but i don't know if it's important
> for
> this issue.
> In my mind when you do a commit a transaction, if something fails, no step
> of the transaction should have been commited, so maybe your database
> do not support transactions.
>
>
I also wonder what the OTM story is. Is it because of the dirty reads? Does
the 2nd level cache make the OTM obsolete?
Re: Help needed for Transaction Rollbacks
Posted by Jean-Yves Sironneau <ep...@gmail.com>.
I think OTM is kind of "deprecated", but i don't know if it's important for
this issue.
In my mind when you do a commit a transaction, if something fails, no step
of the transaction should have been commited, so maybe your database
do not support transactions.
2006/2/21, Vamsi Atluri <vk...@yahoo.com>:
>
> Hello all,
>
> I tested my own solution suggested below, but it still did not work. The
> class that I got for connection was :
>
> org.apache.ojb.broker.util.pooling.ByPassConnection@65476547[
> wrapped connection=com.ibm.ws.rsadapter.jdbc.WSJccConnection@11bb11bb
> ]
>
> Why wouldn't straight commit() and rollback() not work on a Connection?
> Any help is greatly appreciated. Thank you.
>
> Regards,
> -Vamsi
>
> --- Vamsi Atluri <vk...@yahoo.com> 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:
> >
> > 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? Do I "have" to implement OTM (which would be a huge
> > undertaking given the amount of tables we store)? 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: ojb-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: ojb-user-help@db.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
Re: Help needed for Transaction Rollbacks
Posted by Vamsi Atluri <vk...@yahoo.com>.
Hello all,
I tested my own solution suggested below, but it still did not work. The
class that I got for connection was :
org.apache.ojb.broker.util.pooling.ByPassConnection@65476547[
wrapped connection=com.ibm.ws.rsadapter.jdbc.WSJccConnection@11bb11bb
]
Why wouldn't straight commit() and rollback() not work on a Connection?
Any help is greatly appreciated. Thank you.
Regards,
-Vamsi
--- Vamsi Atluri <vk...@yahoo.com> 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:
>
> 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? Do I "have" to implement OTM (which would be a huge
> undertaking given the amount of tables we store)? 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: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org