You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Jim Caserta <sm...@yahoo.com> on 2006/04/10 15:27:37 UTC

RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement

Thomas,

I was reading through this thread and I wantwed to be
sure what you are saying. Is the example below the way
we should be handling transactions? Thanks!


Connection dbConn = null;
try {
		dbConn = Transaction.begin(db2.torque.environment));

		////Do Stuff
		//Commit the transaction (Transaction.commit, should
release connection back to the pool
		Transaction.commit(dbConn);
		Transaction.safeRollback(dbConn);
	}catch(TorqueException e){
		try {
			Transaction.rollback(dbConn);
		} catch (TorqueException e1) {
			Transaction.safeRollback(dbConn);
		}
		}finally {
			if(!dbConn.isClosed()){
				Torque.closeConnection(dbConn);
			}
		}


--- Thomas Fischer <tf...@apache.org> wrote:

> Using commits/rollbacks without explicitly startung
> a connection may look 
> unclean but does not cause any problems in practice
> (at least none known 
> to me). The problem described seems to be the other
> way round: there is no 
> rollback/commit where should be one.
> 
>    Thomas
> 
> On Mon, 27 Mar 2006, Greg Monroe wrote:
> 
> > I did a quick wander thru the Torque code and saw
> one thing
> > that did not look right to me.  Here's some
> background first:
> >
> > All of the Torque Transaction handling is built on
> the
> > Transaction class. This is used primarily by the
> BasePeer
> > methods like doUpdate(Criteria) and the like.
> >
> > These methods are the ones that automatically wrap
> the
> > DB actions as a transaction with rollback.
> >
> > The first thing that didn't look right to me was
> that the
> > Transaction.beginOptional(dbName, useTransaction)
> method
> > is called with the useTransaction arg set to the
> value of
> > criteria.isUseTransation().  This value is set to
> false by
> > default.
> >
> > So, it seems that if you don't set this explicitly
> on your
> > Criteria, you are not using really using
> transactions but
> > you still have the Transaction try/catch code with
> commits and
> > rollbacks.
> >
> > Shouldn't the default for isUseTransactions() be
> true and/or
> > the code handle the false condition without
> calling the
> > extra transaction methods?
> >
> >
> >> -----Original Message-----
> >> From: vivek sar [mailto:vivextra@gmail.com]
> >> Sent: Saturday, March 25, 2006 4:44 AM
> >>
> >> Thanks Thomas for detailed explanation. I haven't
> dig into
> >> the Torque or dbcp code to tell exactly where the
> fault lies.
> >> The way I understand is that the db starts the
> transaction on
> >> your behalf if you don't start one. In case that
> transaction
> >> fails it will try to rollback. The problem I've
> stated is
> >> while the transaction is rolling back the same
> connection is
> >> somehow being used by other query and that's
> causing the
> >> "ORA-01453" and hanging of the connection.
> >>
> >>  I would think it's a problem with dbcp if not
> torque as dbcp
> >> is the one that handles the connection pool. I
> couldn't find
> >> much on the dbcp commons mailing-archiving list,
> but found
> >> tons of similar problems reported by torque
> users, so I think
> >> most of the people do assume it's a Torque
> problem or
> >> somewhere related to it.
> >>
> >>  Yes, if I do handle the transaction myself I
> don't get into
> >> this issue, but still the connection pool should
> handle the
> >> transactions/connections gracefully if it's
> starting one on
> >> your behalf.
> >>
> >>  I've the autocommit turned on (by default), so
> it shouldn't
> >> be problem with that either.
> >>
> >> I am still waiting for the right answer where
> exactly the
> >> problem lies -
> >> 1) How do I get ORA-01453 if I am not starting
> the transaction myself
> >> 2) Why the connection hangs after the ORA-01453
> >>
> >> Thanks,
> >> -vivek
> >>
> >
> > Duke CE Privacy Statement
> > Please be advised that this e-mail and any files
> transmitted with it are confidential communication
> or may otherwise be privileged or confidential and
> are intended solely for the individual or entity to
> whom they are addressed.  If you are not the
> intended recipient you may not rely on the contents
> of this email or any attachments, and we ask that
> you  please not read, copy or retransmit this
> communication, but reply to the sender and destroy
> the email, its contents, and all copies thereof
> immediately.  Any unauthorized dissemination,
> distribution or copying of this communication is
> strictly prohibited.
> >
> >
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> torque-user-unsubscribe@db.apache.org
> > For additional commands, e-mail:
> torque-user-help@db.apache.org
> >
> >
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail:
> torque-user-help@db.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement

Posted by Thomas Fischer <tf...@apache.org>.
You can use catch and finally simultaneously.

try
{
   doSomething();
}
catch (Exception e)
{
   logError(e);
}
finally
{
   closeResources();
}

You can also use several catch blocks.

    Thomas

On Mon, 10 Apr 2006, Jim Caserta wrote:

> One last item..
>
> I can see using ther finally's as we discussed,
> however I can also see using the catches if I want to
> handle different exceptions in different ways.
>
> If I don't use them, I will have no idea what error
> messages to log.
>
> Don't you have the same issue?
>
> Jim
>
> --- Thomas Fischer <tf...@apache.org> wrote:
>
>> It helps if an error occurs in the doStuff() part,
>> because the transaction
>> is closed properly. As a further benefit, all
>> updates/inserts since the
>> last commit/rollback (which is hopefully at the
>> point where you last
>> returned the connection to the pool) are reverted.
>> If no errors occur, the rollback does not hurt,
>> because it is after the
>> commit.
>>
>> By the way, I just committed the documentation page
>> about transactions and
>> connections. See
>>
>>
> http://svn.apache.org/viewcvs.cgi/db/torque/runtime/trunk/xdocs/reference/connections-transactions.xml?view=markup
>>
>>     Thomas
>>
>> On Mon, 10 Apr 2006, Jim Caserta wrote:
>>
>>> Exactly how does that rollback help at that point
>> of
>>> the code Thomas?
>>>
>>> --- Thomas Fischer <tf...@apache.org> wrote:
>>>
>>>> The code now looks good. It's fine to rollback
>> after
>>>> you do the commit.
>>>>
>>>>     Thomas
>>>>
>>>> On Mon, 10 Apr 2006, Jim Caserta wrote:
>>>>
>>>>> So if I'm using the following code below,
>>>>> My question is:
>>>>> Even if the connection is fine and the database
>>>> logic
>>>>> does it's stuff correctly (Do Stuff)..
>>>>> And the connection is NOT closed. It's ok to do
>>>> the
>>>>> "rollback" since the commit worked fine also.
>>>> correct?
>>>>>
>>>>> 	Connection dbConn = null;
>>>>> 	try {
>>>>> 		dbConn =
>>>>> Torque.getConnection("db2.torque.environment");
>>>>> 		////Do Stuff
>>>>> 		dbConn.commit();
>>>>> 	}
>>>>> 	finally {
>>>>> 		if (dbConn == null)	{
>>>>> 			//Connection error logic
>>>>> 		}
>>>>> 		if (!dbConn.isClosed()) {
>>>>> 			dbConn.rollback();
>>>>> 			dbConn.close();
>>>>> 		}
>>>>> 	}
>>>>>
>>>>> --- Thomas Fischer <fi...@seitenbau.net>
>> wrote:
>>>>>
>>>>>>
>>>>>> Jim Caserta <sm...@yahoo.com> schrieb am
>>>>>> 10.04.2006 17:40:05:
>>>>>>
>>>>>>> Sorry about the confusion. I meant using
>>>>>>> Torque.getConnection() and dbConn.close()
>>>> instead
>>>>>> of
>>>>>>> Transaction.begin()..
>>>>>>
>>>>>> For any DB which supports transactions:  _Make
>>>> sure_
>>>>>> that the connection is
>>>>>> in autocommit mode or use Transaction.begin and
>>>>>> Transaction.commit() or do
>>>>>> both. If you do not commit/rollback and are not
>>>> in
>>>>>> autocommit mode you can
>>>>>> run into ugly trouble (e.g. if the transaction
>>>>>> serialization is read
>>>>>> committed, other connections will never see the
>>>>>> changes to the data in the
>>>>>> uncommitted transaction and the like).
>>>>>>
>>>>>>> And if iI was. the following would work well?
>>>>>>>
>>>>>>>
>>>>>>>    Connection dbConn = null;
>>>>>>>    try {
>>>>>>>       // get a connection from the pool
>>>>>>>       dbConn =
>>>>>>> Torque.getConnection(db2.torque.environment);
>>>>>>>       ////Do Stuff
>>>>>>>       //Commit the transaction
>>>>>>>       dbConn.commit();
>>>>>>>    }
>>>>>>>    finally {
>>>>>>>       if (!dbConn.isClosed()) {
>>>>>>>          // some error occurred, try to
>> rollback
>>>>>> and return
>>>>>>> connection to the pool
>>>>>>>          dbConn.close();
>>>>>>>          dbConn.rollback(); //Is this needed?
>>>>>>>       }
>>>>>>>    }
>>>>>>
>>>>>> This is similar to an earlier version I used
>> some
>>>>>> time ago. The problem is
>>>>>> it would throw a NullPointerException in the
>>>> finally
>>>>>> block if
>>>>>> Torque.getConnection() fails. Also, you should
>>>>>> rollback() before you
>>>>>> close().
>>>>>>
>>>>>> Whatever code you use in the end, make sure
>> (i.e.
>>>>>> _test_) that an error in
>>>>>> retrieving/working with the connection is
>> handled
>>>>>> correctly.
>>>>>>
>>>>>>       Thomas
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail:
>>>>>> torque-user-unsubscribe@db.apache.org
>>>>>> For additional commands, e-mail:
>>>>>> torque-user-help@db.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>> __________________________________________________
>>>>> Do You Yahoo!?
>>>>> Tired of spam?  Yahoo! Mail has the best spam
>>>> protection around
>>>>> http://mail.yahoo.com
>>>>>
>>>>>
>>>>
>>>
>>
> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail:
>>>> torque-user-unsubscribe@db.apache.org
>>>>> For additional commands, e-mail:
>>>> torque-user-help@db.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>
>>
> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail:
>>>> torque-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail:
>>>> torque-user-help@db.apache.org
>>>>
>>>>
>>>
>>>
>>> __________________________________________________
>>> Do You Yahoo!?
>>> Tired of spam?  Yahoo! Mail has the best spam
>> protection around
>>> http://mail.yahoo.com
>>>
>>>
>>
> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>> torque-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail:
>> torque-user-help@db.apache.org
>>>
>>>
>>
>>
> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> torque-user-unsubscribe@db.apache.org
>> For additional commands, e-mail:
>> torque-user-help@db.apache.org
>>
>>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement

Posted by Jim Caserta <sm...@yahoo.com>.
One last item.. 

I can see using ther finally's as we discussed,
however I can also see using the catches if I want to 
handle different exceptions in different ways.  

If I don't use them, I will have no idea what error
messages to log. 

Don't you have the same issue?

Jim  

--- Thomas Fischer <tf...@apache.org> wrote:

> It helps if an error occurs in the doStuff() part,
> because the transaction 
> is closed properly. As a further benefit, all
> updates/inserts since the 
> last commit/rollback (which is hopefully at the
> point where you last 
> returned the connection to the pool) are reverted.
> If no errors occur, the rollback does not hurt,
> because it is after the 
> commit.
> 
> By the way, I just committed the documentation page
> about transactions and 
> connections. See
> 
>
http://svn.apache.org/viewcvs.cgi/db/torque/runtime/trunk/xdocs/reference/connections-transactions.xml?view=markup
> 
>     Thomas
> 
> On Mon, 10 Apr 2006, Jim Caserta wrote:
> 
> > Exactly how does that rollback help at that point
> of
> > the code Thomas?
> >
> > --- Thomas Fischer <tf...@apache.org> wrote:
> >
> >> The code now looks good. It's fine to rollback
> after
> >> you do the commit.
> >>
> >>     Thomas
> >>
> >> On Mon, 10 Apr 2006, Jim Caserta wrote:
> >>
> >>> So if I'm using the following code below,
> >>> My question is:
> >>> Even if the connection is fine and the database
> >> logic
> >>> does it's stuff correctly (Do Stuff)..
> >>> And the connection is NOT closed. It's ok to do
> >> the
> >>> "rollback" since the commit worked fine also.
> >> correct?
> >>>
> >>> 	Connection dbConn = null;
> >>> 	try {
> >>> 		dbConn =
> >>> Torque.getConnection("db2.torque.environment");
> >>> 		////Do Stuff
> >>> 		dbConn.commit();
> >>> 	}
> >>> 	finally {
> >>> 		if (dbConn == null)	{
> >>> 			//Connection error logic
> >>> 		}
> >>> 		if (!dbConn.isClosed()) {
> >>> 			dbConn.rollback();
> >>> 			dbConn.close();
> >>> 		}
> >>> 	}
> >>>
> >>> --- Thomas Fischer <fi...@seitenbau.net>
> wrote:
> >>>
> >>>>
> >>>> Jim Caserta <sm...@yahoo.com> schrieb am
> >>>> 10.04.2006 17:40:05:
> >>>>
> >>>>> Sorry about the confusion. I meant using
> >>>>> Torque.getConnection() and dbConn.close()
> >> instead
> >>>> of
> >>>>> Transaction.begin()..
> >>>>
> >>>> For any DB which supports transactions:  _Make
> >> sure_
> >>>> that the connection is
> >>>> in autocommit mode or use Transaction.begin and
> >>>> Transaction.commit() or do
> >>>> both. If you do not commit/rollback and are not
> >> in
> >>>> autocommit mode you can
> >>>> run into ugly trouble (e.g. if the transaction
> >>>> serialization is read
> >>>> committed, other connections will never see the
> >>>> changes to the data in the
> >>>> uncommitted transaction and the like).
> >>>>
> >>>>> And if iI was. the following would work well?
> >>>>>
> >>>>>
> >>>>>    Connection dbConn = null;
> >>>>>    try {
> >>>>>       // get a connection from the pool
> >>>>>       dbConn =
> >>>>> Torque.getConnection(db2.torque.environment);
> >>>>>       ////Do Stuff
> >>>>>       //Commit the transaction
> >>>>>       dbConn.commit();
> >>>>>    }
> >>>>>    finally {
> >>>>>       if (!dbConn.isClosed()) {
> >>>>>          // some error occurred, try to
> rollback
> >>>> and return
> >>>>> connection to the pool
> >>>>>          dbConn.close();
> >>>>>          dbConn.rollback(); //Is this needed?
> >>>>>       }
> >>>>>    }
> >>>>
> >>>> This is similar to an earlier version I used
> some
> >>>> time ago. The problem is
> >>>> it would throw a NullPointerException in the
> >> finally
> >>>> block if
> >>>> Torque.getConnection() fails. Also, you should
> >>>> rollback() before you
> >>>> close().
> >>>>
> >>>> Whatever code you use in the end, make sure
> (i.e.
> >>>> _test_) that an error in
> >>>> retrieving/working with the connection is
> handled
> >>>> correctly.
> >>>>
> >>>>       Thomas
> >>>>
> >>>>
> >>>>
> >>>
> >>
> >
>
---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail:
> >>>> torque-user-unsubscribe@db.apache.org
> >>>> For additional commands, e-mail:
> >>>> torque-user-help@db.apache.org
> >>>>
> >>>>
> >>>
> >>>
> >>>
> __________________________________________________
> >>> Do You Yahoo!?
> >>> Tired of spam?  Yahoo! Mail has the best spam
> >> protection around
> >>> http://mail.yahoo.com
> >>>
> >>>
> >>
> >
>
---------------------------------------------------------------------
> >>> To unsubscribe, e-mail:
> >> torque-user-unsubscribe@db.apache.org
> >>> For additional commands, e-mail:
> >> torque-user-help@db.apache.org
> >>>
> >>>
> >>
> >>
> >
>
---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> >> torque-user-unsubscribe@db.apache.org
> >> For additional commands, e-mail:
> >> torque-user-help@db.apache.org
> >>
> >>
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> torque-user-unsubscribe@db.apache.org
> > For additional commands, e-mail:
> torque-user-help@db.apache.org
> >
> >
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail:
> torque-user-help@db.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement

Posted by Jim Caserta <sm...@yahoo.com>.
Thanks for the info!! It wil help us quite a bit. 

--- Thomas Fischer <tf...@apache.org> wrote:

> It helps if an error occurs in the doStuff() part,
> because the transaction 
> is closed properly. As a further benefit, all
> updates/inserts since the 
> last commit/rollback (which is hopefully at the
> point where you last 
> returned the connection to the pool) are reverted.
> If no errors occur, the rollback does not hurt,
> because it is after the 
> commit.
> 
> By the way, I just committed the documentation page
> about transactions and 
> connections. See
> 
>
http://svn.apache.org/viewcvs.cgi/db/torque/runtime/trunk/xdocs/reference/connections-transactions.xml?view=markup
> 
>     Thomas
> 
> On Mon, 10 Apr 2006, Jim Caserta wrote:
> 
> > Exactly how does that rollback help at that point
> of
> > the code Thomas?
> >
> > --- Thomas Fischer <tf...@apache.org> wrote:
> >
> >> The code now looks good. It's fine to rollback
> after
> >> you do the commit.
> >>
> >>     Thomas
> >>
> >> On Mon, 10 Apr 2006, Jim Caserta wrote:
> >>
> >>> So if I'm using the following code below,
> >>> My question is:
> >>> Even if the connection is fine and the database
> >> logic
> >>> does it's stuff correctly (Do Stuff)..
> >>> And the connection is NOT closed. It's ok to do
> >> the
> >>> "rollback" since the commit worked fine also.
> >> correct?
> >>>
> >>> 	Connection dbConn = null;
> >>> 	try {
> >>> 		dbConn =
> >>> Torque.getConnection("db2.torque.environment");
> >>> 		////Do Stuff
> >>> 		dbConn.commit();
> >>> 	}
> >>> 	finally {
> >>> 		if (dbConn == null)	{
> >>> 			//Connection error logic
> >>> 		}
> >>> 		if (!dbConn.isClosed()) {
> >>> 			dbConn.rollback();
> >>> 			dbConn.close();
> >>> 		}
> >>> 	}
> >>>
> >>> --- Thomas Fischer <fi...@seitenbau.net>
> wrote:
> >>>
> >>>>
> >>>> Jim Caserta <sm...@yahoo.com> schrieb am
> >>>> 10.04.2006 17:40:05:
> >>>>
> >>>>> Sorry about the confusion. I meant using
> >>>>> Torque.getConnection() and dbConn.close()
> >> instead
> >>>> of
> >>>>> Transaction.begin()..
> >>>>
> >>>> For any DB which supports transactions:  _Make
> >> sure_
> >>>> that the connection is
> >>>> in autocommit mode or use Transaction.begin and
> >>>> Transaction.commit() or do
> >>>> both. If you do not commit/rollback and are not
> >> in
> >>>> autocommit mode you can
> >>>> run into ugly trouble (e.g. if the transaction
> >>>> serialization is read
> >>>> committed, other connections will never see the
> >>>> changes to the data in the
> >>>> uncommitted transaction and the like).
> >>>>
> >>>>> And if iI was. the following would work well?
> >>>>>
> >>>>>
> >>>>>    Connection dbConn = null;
> >>>>>    try {
> >>>>>       // get a connection from the pool
> >>>>>       dbConn =
> >>>>> Torque.getConnection(db2.torque.environment);
> >>>>>       ////Do Stuff
> >>>>>       //Commit the transaction
> >>>>>       dbConn.commit();
> >>>>>    }
> >>>>>    finally {
> >>>>>       if (!dbConn.isClosed()) {
> >>>>>          // some error occurred, try to
> rollback
> >>>> and return
> >>>>> connection to the pool
> >>>>>          dbConn.close();
> >>>>>          dbConn.rollback(); //Is this needed?
> >>>>>       }
> >>>>>    }
> >>>>
> >>>> This is similar to an earlier version I used
> some
> >>>> time ago. The problem is
> >>>> it would throw a NullPointerException in the
> >> finally
> >>>> block if
> >>>> Torque.getConnection() fails. Also, you should
> >>>> rollback() before you
> >>>> close().
> >>>>
> >>>> Whatever code you use in the end, make sure
> (i.e.
> >>>> _test_) that an error in
> >>>> retrieving/working with the connection is
> handled
> >>>> correctly.
> >>>>
> >>>>       Thomas
> >>>>
> >>>>
> >>>>
> >>>
> >>
> >
>
---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail:
> >>>> torque-user-unsubscribe@db.apache.org
> >>>> For additional commands, e-mail:
> >>>> torque-user-help@db.apache.org
> >>>>
> >>>>
> >>>
> >>>
> >>>
> __________________________________________________
> >>> Do You Yahoo!?
> >>> Tired of spam?  Yahoo! Mail has the best spam
> >> protection around
> >>> http://mail.yahoo.com
> >>>
> >>>
> >>
> >
>
---------------------------------------------------------------------
> >>> To unsubscribe, e-mail:
> >> torque-user-unsubscribe@db.apache.org
> >>> For additional commands, e-mail:
> >> torque-user-help@db.apache.org
> >>>
> >>>
> >>
> >>
> >
>
---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> >> torque-user-unsubscribe@db.apache.org
> >> For additional commands, e-mail:
> >> torque-user-help@db.apache.org
> >>
> >>
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> torque-user-unsubscribe@db.apache.org
> > For additional commands, e-mail:
> torque-user-help@db.apache.org
> >
> >
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail:
> torque-user-help@db.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement

Posted by Thomas Fischer <tf...@apache.org>.
It helps if an error occurs in the doStuff() part, because the transaction 
is closed properly. As a further benefit, all updates/inserts since the 
last commit/rollback (which is hopefully at the point where you last 
returned the connection to the pool) are reverted.
If no errors occur, the rollback does not hurt, because it is after the 
commit.

By the way, I just committed the documentation page about transactions and 
connections. See

http://svn.apache.org/viewcvs.cgi/db/torque/runtime/trunk/xdocs/reference/connections-transactions.xml?view=markup

    Thomas

On Mon, 10 Apr 2006, Jim Caserta wrote:

> Exactly how does that rollback help at that point of
> the code Thomas?
>
> --- Thomas Fischer <tf...@apache.org> wrote:
>
>> The code now looks good. It's fine to rollback after
>> you do the commit.
>>
>>     Thomas
>>
>> On Mon, 10 Apr 2006, Jim Caserta wrote:
>>
>>> So if I'm using the following code below,
>>> My question is:
>>> Even if the connection is fine and the database
>> logic
>>> does it's stuff correctly (Do Stuff)..
>>> And the connection is NOT closed. It's ok to do
>> the
>>> "rollback" since the commit worked fine also.
>> correct?
>>>
>>> 	Connection dbConn = null;
>>> 	try {
>>> 		dbConn =
>>> Torque.getConnection("db2.torque.environment");
>>> 		////Do Stuff
>>> 		dbConn.commit();
>>> 	}
>>> 	finally {
>>> 		if (dbConn == null)	{
>>> 			//Connection error logic
>>> 		}
>>> 		if (!dbConn.isClosed()) {
>>> 			dbConn.rollback();
>>> 			dbConn.close();
>>> 		}
>>> 	}
>>>
>>> --- Thomas Fischer <fi...@seitenbau.net> wrote:
>>>
>>>>
>>>> Jim Caserta <sm...@yahoo.com> schrieb am
>>>> 10.04.2006 17:40:05:
>>>>
>>>>> Sorry about the confusion. I meant using
>>>>> Torque.getConnection() and dbConn.close()
>> instead
>>>> of
>>>>> Transaction.begin()..
>>>>
>>>> For any DB which supports transactions:  _Make
>> sure_
>>>> that the connection is
>>>> in autocommit mode or use Transaction.begin and
>>>> Transaction.commit() or do
>>>> both. If you do not commit/rollback and are not
>> in
>>>> autocommit mode you can
>>>> run into ugly trouble (e.g. if the transaction
>>>> serialization is read
>>>> committed, other connections will never see the
>>>> changes to the data in the
>>>> uncommitted transaction and the like).
>>>>
>>>>> And if iI was. the following would work well?
>>>>>
>>>>>
>>>>>    Connection dbConn = null;
>>>>>    try {
>>>>>       // get a connection from the pool
>>>>>       dbConn =
>>>>> Torque.getConnection(db2.torque.environment);
>>>>>       ////Do Stuff
>>>>>       //Commit the transaction
>>>>>       dbConn.commit();
>>>>>    }
>>>>>    finally {
>>>>>       if (!dbConn.isClosed()) {
>>>>>          // some error occurred, try to rollback
>>>> and return
>>>>> connection to the pool
>>>>>          dbConn.close();
>>>>>          dbConn.rollback(); //Is this needed?
>>>>>       }
>>>>>    }
>>>>
>>>> This is similar to an earlier version I used some
>>>> time ago. The problem is
>>>> it would throw a NullPointerException in the
>> finally
>>>> block if
>>>> Torque.getConnection() fails. Also, you should
>>>> rollback() before you
>>>> close().
>>>>
>>>> Whatever code you use in the end, make sure (i.e.
>>>> _test_) that an error in
>>>> retrieving/working with the connection is handled
>>>> correctly.
>>>>
>>>>       Thomas
>>>>
>>>>
>>>>
>>>
>>
> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail:
>>>> torque-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail:
>>>> torque-user-help@db.apache.org
>>>>
>>>>
>>>
>>>
>>> __________________________________________________
>>> Do You Yahoo!?
>>> Tired of spam?  Yahoo! Mail has the best spam
>> protection around
>>> http://mail.yahoo.com
>>>
>>>
>>
> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>> torque-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail:
>> torque-user-help@db.apache.org
>>>
>>>
>>
>>
> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> torque-user-unsubscribe@db.apache.org
>> For additional commands, e-mail:
>> torque-user-help@db.apache.org
>>
>>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement

Posted by Jim Caserta <sm...@yahoo.com>.
Exactly how does that rollback help at that point of
the code Thomas? 

--- Thomas Fischer <tf...@apache.org> wrote:

> The code now looks good. It's fine to rollback after
> you do the commit.
> 
>     Thomas
> 
> On Mon, 10 Apr 2006, Jim Caserta wrote:
> 
> > So if I'm using the following code below,
> > My question is:
> > Even if the connection is fine and the database
> logic
> > does it's stuff correctly (Do Stuff)..
> > And the connection is NOT closed. It's ok to do
> the
> > "rollback" since the commit worked fine also.
> correct?
> >
> > 	Connection dbConn = null;
> > 	try {
> > 		dbConn =
> > Torque.getConnection("db2.torque.environment");
> > 		////Do Stuff
> > 		dbConn.commit();
> > 	}
> > 	finally {
> > 		if (dbConn == null)	{
> > 			//Connection error logic
> > 		}
> > 		if (!dbConn.isClosed()) {
> > 			dbConn.rollback();
> > 			dbConn.close();
> > 		}
> > 	}
> >
> > --- Thomas Fischer <fi...@seitenbau.net> wrote:
> >
> >>
> >> Jim Caserta <sm...@yahoo.com> schrieb am
> >> 10.04.2006 17:40:05:
> >>
> >>> Sorry about the confusion. I meant using
> >>> Torque.getConnection() and dbConn.close()
> instead
> >> of
> >>> Transaction.begin()..
> >>
> >> For any DB which supports transactions:  _Make
> sure_
> >> that the connection is
> >> in autocommit mode or use Transaction.begin and
> >> Transaction.commit() or do
> >> both. If you do not commit/rollback and are not
> in
> >> autocommit mode you can
> >> run into ugly trouble (e.g. if the transaction
> >> serialization is read
> >> committed, other connections will never see the
> >> changes to the data in the
> >> uncommitted transaction and the like).
> >>
> >>> And if iI was. the following would work well?
> >>>
> >>>
> >>>    Connection dbConn = null;
> >>>    try {
> >>>       // get a connection from the pool
> >>>       dbConn =
> >>> Torque.getConnection(db2.torque.environment);
> >>>       ////Do Stuff
> >>>       //Commit the transaction
> >>>       dbConn.commit();
> >>>    }
> >>>    finally {
> >>>       if (!dbConn.isClosed()) {
> >>>          // some error occurred, try to rollback
> >> and return
> >>> connection to the pool
> >>>          dbConn.close();
> >>>          dbConn.rollback(); //Is this needed?
> >>>       }
> >>>    }
> >>
> >> This is similar to an earlier version I used some
> >> time ago. The problem is
> >> it would throw a NullPointerException in the
> finally
> >> block if
> >> Torque.getConnection() fails. Also, you should
> >> rollback() before you
> >> close().
> >>
> >> Whatever code you use in the end, make sure (i.e.
> >> _test_) that an error in
> >> retrieving/working with the connection is handled
> >> correctly.
> >>
> >>       Thomas
> >>
> >>
> >>
> >
>
---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> >> torque-user-unsubscribe@db.apache.org
> >> For additional commands, e-mail:
> >> torque-user-help@db.apache.org
> >>
> >>
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> torque-user-unsubscribe@db.apache.org
> > For additional commands, e-mail:
> torque-user-help@db.apache.org
> >
> >
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail:
> torque-user-help@db.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement

Posted by Thomas Fischer <tf...@apache.org>.
The code now looks good. It's fine to rollback after you do the commit.

    Thomas

On Mon, 10 Apr 2006, Jim Caserta wrote:

> So if I'm using the following code below,
> My question is:
> Even if the connection is fine and the database logic
> does it's stuff correctly (Do Stuff)..
> And the connection is NOT closed. It's ok to do the
> "rollback" since the commit worked fine also. correct?
>
> 	Connection dbConn = null;
> 	try {
> 		dbConn =
> Torque.getConnection("db2.torque.environment");
> 		////Do Stuff
> 		dbConn.commit();
> 	}
> 	finally {
> 		if (dbConn == null)	{
> 			//Connection error logic
> 		}
> 		if (!dbConn.isClosed()) {
> 			dbConn.rollback();
> 			dbConn.close();
> 		}
> 	}
>
> --- Thomas Fischer <fi...@seitenbau.net> wrote:
>
>>
>> Jim Caserta <sm...@yahoo.com> schrieb am
>> 10.04.2006 17:40:05:
>>
>>> Sorry about the confusion. I meant using
>>> Torque.getConnection() and dbConn.close() instead
>> of
>>> Transaction.begin()..
>>
>> For any DB which supports transactions:  _Make sure_
>> that the connection is
>> in autocommit mode or use Transaction.begin and
>> Transaction.commit() or do
>> both. If you do not commit/rollback and are not in
>> autocommit mode you can
>> run into ugly trouble (e.g. if the transaction
>> serialization is read
>> committed, other connections will never see the
>> changes to the data in the
>> uncommitted transaction and the like).
>>
>>> And if iI was. the following would work well?
>>>
>>>
>>>    Connection dbConn = null;
>>>    try {
>>>       // get a connection from the pool
>>>       dbConn =
>>> Torque.getConnection(db2.torque.environment);
>>>       ////Do Stuff
>>>       //Commit the transaction
>>>       dbConn.commit();
>>>    }
>>>    finally {
>>>       if (!dbConn.isClosed()) {
>>>          // some error occurred, try to rollback
>> and return
>>> connection to the pool
>>>          dbConn.close();
>>>          dbConn.rollback(); //Is this needed?
>>>       }
>>>    }
>>
>> This is similar to an earlier version I used some
>> time ago. The problem is
>> it would throw a NullPointerException in the finally
>> block if
>> Torque.getConnection() fails. Also, you should
>> rollback() before you
>> close().
>>
>> Whatever code you use in the end, make sure (i.e.
>> _test_) that an error in
>> retrieving/working with the connection is handled
>> correctly.
>>
>>       Thomas
>>
>>
>>
> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> torque-user-unsubscribe@db.apache.org
>> For additional commands, e-mail:
>> torque-user-help@db.apache.org
>>
>>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement

Posted by Jim Caserta <sm...@yahoo.com>.
So if I'm using the following code below, 
My question is: 
Even if the connection is fine and the database logic
does it's stuff correctly (Do Stuff).. 
And the connection is NOT closed. It's ok to do the
"rollback" since the commit worked fine also. correct?

	Connection dbConn = null;
	try { 
		dbConn =
Torque.getConnection("db2.torque.environment");
		////Do Stuff
		dbConn.commit();
	}
	finally {
		if (dbConn == null)	{
			//Connection error logic
		}
		if (!dbConn.isClosed()) {
			dbConn.rollback();
			dbConn.close();
		}
	}

--- Thomas Fischer <fi...@seitenbau.net> wrote:

> 
> Jim Caserta <sm...@yahoo.com> schrieb am
> 10.04.2006 17:40:05:
> 
> > Sorry about the confusion. I meant using
> > Torque.getConnection() and dbConn.close() instead
> of
> > Transaction.begin()..
> 
> For any DB which supports transactions:  _Make sure_
> that the connection is
> in autocommit mode or use Transaction.begin and
> Transaction.commit() or do
> both. If you do not commit/rollback and are not in
> autocommit mode you can
> run into ugly trouble (e.g. if the transaction
> serialization is read
> committed, other connections will never see the
> changes to the data in the
> uncommitted transaction and the like).
> 
> > And if iI was. the following would work well?
> >
> >
> >    Connection dbConn = null;
> >    try {
> >       // get a connection from the pool
> >       dbConn =
> > Torque.getConnection(db2.torque.environment);
> >       ////Do Stuff
> >       //Commit the transaction
> >       dbConn.commit();
> >    }
> >    finally {
> >       if (!dbConn.isClosed()) {
> >          // some error occurred, try to rollback
> and return
> > connection to the pool
> >          dbConn.close();
> >          dbConn.rollback(); //Is this needed?
> >       }
> >    }
> 
> This is similar to an earlier version I used some
> time ago. The problem is
> it would throw a NullPointerException in the finally
> block if
> Torque.getConnection() fails. Also, you should
> rollback() before you
> close().
> 
> Whatever code you use in the end, make sure (i.e.
> _test_) that an error in
> retrieving/working with the connection is handled
> correctly.
> 
>       Thomas
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail:
> torque-user-help@db.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement

Posted by Thomas Fischer <fi...@seitenbau.net>.
Jim Caserta <sm...@yahoo.com> schrieb am 10.04.2006 17:40:05:

> Sorry about the confusion. I meant using
> Torque.getConnection() and dbConn.close() instead of
> Transaction.begin()..

For any DB which supports transactions:  _Make sure_ that the connection is
in autocommit mode or use Transaction.begin and Transaction.commit() or do
both. If you do not commit/rollback and are not in autocommit mode you can
run into ugly trouble (e.g. if the transaction serialization is read
committed, other connections will never see the changes to the data in the
uncommitted transaction and the like).

> And if iI was. the following would work well?
>
>
>    Connection dbConn = null;
>    try {
>       // get a connection from the pool
>       dbConn =
> Torque.getConnection(db2.torque.environment);
>       ////Do Stuff
>       //Commit the transaction
>       dbConn.commit();
>    }
>    finally {
>       if (!dbConn.isClosed()) {
>          // some error occurred, try to rollback and return
> connection to the pool
>          dbConn.close();
>          dbConn.rollback(); //Is this needed?
>       }
>    }

This is similar to an earlier version I used some time ago. The problem is
it would throw a NullPointerException in the finally block if
Torque.getConnection() fails. Also, you should rollback() before you
close().

Whatever code you use in the end, make sure (i.e. _test_) that an error in
retrieving/working with the connection is handled correctly.

      Thomas


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement

Posted by Jim Caserta <sm...@yahoo.com>.
Sorry about the confusion. I meant using
Torque.getConnection() and dbConn.close() instead of  
Transaction.begin()..

And if iI was. the following would work well? 


	Connection dbConn = null;
	try { 
		// get a connection from the pool
		dbConn =
Torque.getConnection(db2.torque.environment);
		////Do Stuff
		//Commit the transaction 
		dbConn.commit();
	}
	finally {
		if (!dbConn.isClosed()) {
			// some error occurred, try to rollback and return
connection to the pool
			dbConn.close();
			dbConn.rollback(); //Is this needed?
		}
	}

--- Thomas Fischer <fi...@seitenbau.net> wrote:

> Jim,
> 
> I'm not sure if you can "not use a transaction".
> E.g. in oracle, every sql
> select/update/delete/insert command automatically
> starts a transaction. The
> closest you can come to "not using transactions" in
> oracle is autocommit
> mode where every sql command is wrapped in its own
> transaction. I'm not
> sure what the situation is for DB2.
> 
> In my experience, you can use the same code without
> problems if you are in
> autocommit mode in oracle, but this may vary from
> database to database.
> From my oracle-based experience, I would try to use
> exactly the same code,
> and see if its works in all cases (with/without
> errors). Only if this does
> not work, I'd try to use Torque.getConnection() and
> dbConn.close() instead
> of Transaction.begin() and
> Transaction.commit()/Transaction.safeRollback.
> But to be sure, check the DB2 docs.
> 
>     Thomas
> 
> Jim Caserta <sm...@yahoo.com> schrieb am
> 10.04.2006 16:54:28:
> 
> > Thomas,
> >
> > I see what you mean...
> >
> > I'm assuming I can take the same approach if I'm
> Not
> > using a Transaction. Correct?
> >
> > Jim
> >
> > --- Thomas Fischer <fi...@seitenbau.net> wrote:
> >
> > > Hi,
> > >
> > > I am using the following code:
> > >
> > > Connection dbConn = null;
> > > try
> > > {
> > >     dbConn =
> > > Transaction.begin(db2.torque.environment));
> > >
> > >     ////Do Stuff
> > >
> > >     //Commit the transaction (Transaction.commit
> > > releases connection back
> > > to the pool)
> > >     Transaction.commit(dbConn);
> > >     dbConn = null;
> > > }
> > > finally
> > > {
> > >     if (connection != null)
> > >     {
> > >         // some error occurred, try to rollback
> and
> > > return connection to
> > > pool
> > >         Transaction.safeRollback(dbConn);
> > >         dbConn = null;
> > >     }
> > > }
> > >
> > > It is safer to use a finally block than a catch
> > > block. In some ugly cases,
> > > you get errors and not exceptions, and they are
> not
> > > caught by
> > > catch(exception). Also, the finally block works
> even
> > > if you return inside
> > > the block.
> > >
> > > I have also written some docs about this, but I
> have
> > > forgotten to commit it
> > > :-(.
> > >
> > >     Thomas
> > >
> > >
> > > Jim Caserta <sm...@yahoo.com> schrieb am
> > > 10.04.2006 15:27:37:
> > >
> > > > Thomas,
> > > >
> > > > I was reading through this thread and I
> wantwed to
> > > be
> > > > sure what you are saying. Is the example below
> the
> > > way
> > > > we should be handling transactions? Thanks!
> > > >
> > > >
> > > > Connection dbConn = null;
> > > > try {
> > > >       dbConn =
> > > Transaction.begin(db2.torque.environment));
> > > >
> > > >       ////Do Stuff
> > > >       //Commit the transaction
> > > (Transaction.commit, should
> > > > release connection back to the pool
> > > >       Transaction.commit(dbConn);
> > > >       Transaction.safeRollback(dbConn);
> > > >    }catch(TorqueException e){
> > > >       try {
> > > >          Transaction.rollback(dbConn);
> > > >       } catch (TorqueException e1) {
> > > >          Transaction.safeRollback(dbConn);
> > > >       }
> > > >       }finally {
> > > >          if(!dbConn.isClosed()){
> > > >             Torque.closeConnection(dbConn);
> > > >          }
> > > >       }
> > > >
> > > >
> > > > --- Thomas Fischer <tf...@apache.org>
> wrote:
> > > >
> > > > > Using commits/rollbacks without explicitly
> > > startung
> > > > > a connection may look
> > > > > unclean but does not cause any problems in
> > > practice
> > > > > (at least none known
> > > > > to me). The problem described seems to be
> the
> > > other
> > > > > way round: there is no
> > > > > rollback/commit where should be one.
> > > > >
> > > > >    Thomas
> > > > >
> > > > > On Mon, 27 Mar 2006, Greg Monroe wrote:
> > > > >
> > > > > > I did a quick wander thru the Torque code
> and
> > > saw
> > > > > one thing
> > > > > > that did not look right to me.  Here's
> some
> > > > > background first:
> > > > > >
> > > > > > All of the Torque Transaction handling is
> > > built on
> > > > > the
> > > > > > Transaction class. This is used primarily
> by
> > > the
> > > > > BasePeer
> > > > > > methods like doUpdate(Criteria) and the
> like.
> > > > > >
> > > > > > These methods are the ones that
> automatically
> > > wrap
> > > > > the
> > > > > > DB actions as a transaction with rollback.
> > > > > >
> > > > > > The first thing that didn't look right to
> me
> > > was
> > > > > that the
> > > > > > Transaction.beginOptional(dbName,
> > > useTransaction)
> > > > > method
> > > > > > is called with the useTransaction arg set
> to
> > > the
> > > > > value of
> > > > > > criteria.isUseTransation().  This value is
> set
> > > to
> > > > > false by
> > > > > > default.
> > > > > >
> > > > > > So, it seems that if you don't set this
> > > explicitly
> > > > > on your
> > > > > > Criteria, you are not using really using
> > > > > transactions but
> > > > > > you still have the Transaction try/catch
> code
> > > with
> > > > > commits and
> > > > > > rollbacks.
> > > > > >
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement

Posted by Thomas Fischer <fi...@seitenbau.net>.
Jim,

I'm not sure if you can "not use a transaction". E.g. in oracle, every sql
select/update/delete/insert command automatically starts a transaction. The
closest you can come to "not using transactions" in oracle is autocommit
mode where every sql command is wrapped in its own transaction. I'm not
sure what the situation is for DB2.

In my experience, you can use the same code without problems if you are in
autocommit mode in oracle, but this may vary from database to database.
>From my oracle-based experience, I would try to use exactly the same code,
and see if its works in all cases (with/without errors). Only if this does
not work, I'd try to use Torque.getConnection() and dbConn.close() instead
of Transaction.begin() and Transaction.commit()/Transaction.safeRollback.
But to be sure, check the DB2 docs.

    Thomas

Jim Caserta <sm...@yahoo.com> schrieb am 10.04.2006 16:54:28:

> Thomas,
>
> I see what you mean...
>
> I'm assuming I can take the same approach if I'm Not
> using a Transaction. Correct?
>
> Jim
>
> --- Thomas Fischer <fi...@seitenbau.net> wrote:
>
> > Hi,
> >
> > I am using the following code:
> >
> > Connection dbConn = null;
> > try
> > {
> >     dbConn =
> > Transaction.begin(db2.torque.environment));
> >
> >     ////Do Stuff
> >
> >     //Commit the transaction (Transaction.commit
> > releases connection back
> > to the pool)
> >     Transaction.commit(dbConn);
> >     dbConn = null;
> > }
> > finally
> > {
> >     if (connection != null)
> >     {
> >         // some error occurred, try to rollback and
> > return connection to
> > pool
> >         Transaction.safeRollback(dbConn);
> >         dbConn = null;
> >     }
> > }
> >
> > It is safer to use a finally block than a catch
> > block. In some ugly cases,
> > you get errors and not exceptions, and they are not
> > caught by
> > catch(exception). Also, the finally block works even
> > if you return inside
> > the block.
> >
> > I have also written some docs about this, but I have
> > forgotten to commit it
> > :-(.
> >
> >     Thomas
> >
> >
> > Jim Caserta <sm...@yahoo.com> schrieb am
> > 10.04.2006 15:27:37:
> >
> > > Thomas,
> > >
> > > I was reading through this thread and I wantwed to
> > be
> > > sure what you are saying. Is the example below the
> > way
> > > we should be handling transactions? Thanks!
> > >
> > >
> > > Connection dbConn = null;
> > > try {
> > >       dbConn =
> > Transaction.begin(db2.torque.environment));
> > >
> > >       ////Do Stuff
> > >       //Commit the transaction
> > (Transaction.commit, should
> > > release connection back to the pool
> > >       Transaction.commit(dbConn);
> > >       Transaction.safeRollback(dbConn);
> > >    }catch(TorqueException e){
> > >       try {
> > >          Transaction.rollback(dbConn);
> > >       } catch (TorqueException e1) {
> > >          Transaction.safeRollback(dbConn);
> > >       }
> > >       }finally {
> > >          if(!dbConn.isClosed()){
> > >             Torque.closeConnection(dbConn);
> > >          }
> > >       }
> > >
> > >
> > > --- Thomas Fischer <tf...@apache.org> wrote:
> > >
> > > > Using commits/rollbacks without explicitly
> > startung
> > > > a connection may look
> > > > unclean but does not cause any problems in
> > practice
> > > > (at least none known
> > > > to me). The problem described seems to be the
> > other
> > > > way round: there is no
> > > > rollback/commit where should be one.
> > > >
> > > >    Thomas
> > > >
> > > > On Mon, 27 Mar 2006, Greg Monroe wrote:
> > > >
> > > > > I did a quick wander thru the Torque code and
> > saw
> > > > one thing
> > > > > that did not look right to me.  Here's some
> > > > background first:
> > > > >
> > > > > All of the Torque Transaction handling is
> > built on
> > > > the
> > > > > Transaction class. This is used primarily by
> > the
> > > > BasePeer
> > > > > methods like doUpdate(Criteria) and the like.
> > > > >
> > > > > These methods are the ones that automatically
> > wrap
> > > > the
> > > > > DB actions as a transaction with rollback.
> > > > >
> > > > > The first thing that didn't look right to me
> > was
> > > > that the
> > > > > Transaction.beginOptional(dbName,
> > useTransaction)
> > > > method
> > > > > is called with the useTransaction arg set to
> > the
> > > > value of
> > > > > criteria.isUseTransation().  This value is set
> > to
> > > > false by
> > > > > default.
> > > > >
> > > > > So, it seems that if you don't set this
> > explicitly
> > > > on your
> > > > > Criteria, you are not using really using
> > > > transactions but
> > > > > you still have the Transaction try/catch code
> > with
> > > > commits and
> > > > > rollbacks.
> > > > >
> > > > > Shouldn't the default for isUseTransactions()
> > be
> > > > true and/or
> > > > > the code handle the false condition without
> > > > calling the
> > > > > extra transaction methods?
> > > > >
> > > > >
> > > > >> -----Original Message-----
> > > > >> From: vivek sar [mailto:vivextra@gmail.com]
> > > > >> Sent: Saturday, March 25, 2006 4:44 AM
> > > > >>
> > > > >> Thanks Thomas for detailed explanation. I
> > haven't
> > > > dig into
> > > > >> the Torque or dbcp code to tell exactly where
> > the
> > > > fault lies.
> > > > >> The way I understand is that the db starts
> > the
> > > > transaction on
> > > > >> your behalf if you don't start one. In case
> > that
> > > > transaction
> > > > >> fails it will try to rollback. The problem
> > I've
> > > > stated is
> > > > >> while the transaction is rolling back the
> > same
> > > > connection is
> > > > >> somehow being used by other query and that's
> > > > causing the
> > > > >> "ORA-01453" and hanging of the connection.
> > > > >>
> > > > >>  I would think it's a problem with dbcp if
> > not
> > > > torque as dbcp
> > > > >> is the one that handles the connection pool.
> > I
> > > > couldn't find
> > > > >> much on the dbcp commons mailing-archiving
> > list,
> > > > but found
> > > > >> tons of similar problems reported by torque
> > > > users, so I think
> > > > >> most of the people do assume it's a Torque
> > > > problem or
> > > > >> somewhere related to it.
> > > > >>
> > > > >>  Yes, if I do handle the transaction myself I
> > > > don't get into
> > > > >> this issue, but still the connection pool
> > should
> > > > handle the
> > > > >> transactions/connections gracefully if it's
> > > > starting one on
> > > > >> your behalf.
> > > > >>
> > > > >>  I've the autocommit turned on (by default),
> > so
> >
> === message truncated ===
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement

Posted by Jim Caserta <sm...@yahoo.com>.
Thomas,

I see what you mean...

I'm assuming I can take the same approach if I'm Not
using a Transaction. Correct? 

Jim

--- Thomas Fischer <fi...@seitenbau.net> wrote:

> Hi,
> 
> I am using the following code:
> 
> Connection dbConn = null;
> try
> {
>     dbConn =
> Transaction.begin(db2.torque.environment));
> 
>     ////Do Stuff
> 
>     //Commit the transaction (Transaction.commit
> releases connection back
> to the pool)
>     Transaction.commit(dbConn);
>     dbConn = null;
> }
> finally
> {
>     if (connection != null)
>     {
>         // some error occurred, try to rollback and
> return connection to
> pool
>         Transaction.safeRollback(dbConn);
>         dbConn = null;
>     }
> }
> 
> It is safer to use a finally block than a catch
> block. In some ugly cases,
> you get errors and not exceptions, and they are not
> caught by
> catch(exception). Also, the finally block works even
> if you return inside
> the block.
> 
> I have also written some docs about this, but I have
> forgotten to commit it
> :-(.
> 
>     Thomas
> 
> 
> Jim Caserta <sm...@yahoo.com> schrieb am
> 10.04.2006 15:27:37:
> 
> > Thomas,
> >
> > I was reading through this thread and I wantwed to
> be
> > sure what you are saying. Is the example below the
> way
> > we should be handling transactions? Thanks!
> >
> >
> > Connection dbConn = null;
> > try {
> >       dbConn =
> Transaction.begin(db2.torque.environment));
> >
> >       ////Do Stuff
> >       //Commit the transaction
> (Transaction.commit, should
> > release connection back to the pool
> >       Transaction.commit(dbConn);
> >       Transaction.safeRollback(dbConn);
> >    }catch(TorqueException e){
> >       try {
> >          Transaction.rollback(dbConn);
> >       } catch (TorqueException e1) {
> >          Transaction.safeRollback(dbConn);
> >       }
> >       }finally {
> >          if(!dbConn.isClosed()){
> >             Torque.closeConnection(dbConn);
> >          }
> >       }
> >
> >
> > --- Thomas Fischer <tf...@apache.org> wrote:
> >
> > > Using commits/rollbacks without explicitly
> startung
> > > a connection may look
> > > unclean but does not cause any problems in
> practice
> > > (at least none known
> > > to me). The problem described seems to be the
> other
> > > way round: there is no
> > > rollback/commit where should be one.
> > >
> > >    Thomas
> > >
> > > On Mon, 27 Mar 2006, Greg Monroe wrote:
> > >
> > > > I did a quick wander thru the Torque code and
> saw
> > > one thing
> > > > that did not look right to me.  Here's some
> > > background first:
> > > >
> > > > All of the Torque Transaction handling is
> built on
> > > the
> > > > Transaction class. This is used primarily by
> the
> > > BasePeer
> > > > methods like doUpdate(Criteria) and the like.
> > > >
> > > > These methods are the ones that automatically
> wrap
> > > the
> > > > DB actions as a transaction with rollback.
> > > >
> > > > The first thing that didn't look right to me
> was
> > > that the
> > > > Transaction.beginOptional(dbName,
> useTransaction)
> > > method
> > > > is called with the useTransaction arg set to
> the
> > > value of
> > > > criteria.isUseTransation().  This value is set
> to
> > > false by
> > > > default.
> > > >
> > > > So, it seems that if you don't set this
> explicitly
> > > on your
> > > > Criteria, you are not using really using
> > > transactions but
> > > > you still have the Transaction try/catch code
> with
> > > commits and
> > > > rollbacks.
> > > >
> > > > Shouldn't the default for isUseTransactions()
> be
> > > true and/or
> > > > the code handle the false condition without
> > > calling the
> > > > extra transaction methods?
> > > >
> > > >
> > > >> -----Original Message-----
> > > >> From: vivek sar [mailto:vivextra@gmail.com]
> > > >> Sent: Saturday, March 25, 2006 4:44 AM
> > > >>
> > > >> Thanks Thomas for detailed explanation. I
> haven't
> > > dig into
> > > >> the Torque or dbcp code to tell exactly where
> the
> > > fault lies.
> > > >> The way I understand is that the db starts
> the
> > > transaction on
> > > >> your behalf if you don't start one. In case
> that
> > > transaction
> > > >> fails it will try to rollback. The problem
> I've
> > > stated is
> > > >> while the transaction is rolling back the
> same
> > > connection is
> > > >> somehow being used by other query and that's
> > > causing the
> > > >> "ORA-01453" and hanging of the connection.
> > > >>
> > > >>  I would think it's a problem with dbcp if
> not
> > > torque as dbcp
> > > >> is the one that handles the connection pool.
> I
> > > couldn't find
> > > >> much on the dbcp commons mailing-archiving
> list,
> > > but found
> > > >> tons of similar problems reported by torque
> > > users, so I think
> > > >> most of the people do assume it's a Torque
> > > problem or
> > > >> somewhere related to it.
> > > >>
> > > >>  Yes, if I do handle the transaction myself I
> > > don't get into
> > > >> this issue, but still the connection pool
> should
> > > handle the
> > > >> transactions/connections gracefully if it's
> > > starting one on
> > > >> your behalf.
> > > >>
> > > >>  I've the autocommit turned on (by default),
> so
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement

Posted by Thomas Fischer <fi...@seitenbau.net>.
Hi,

I am using the following code:

Connection dbConn = null;
try
{
    dbConn = Transaction.begin(db2.torque.environment));

    ////Do Stuff

    //Commit the transaction (Transaction.commit releases connection back
to the pool)
    Transaction.commit(dbConn);
    dbConn = null;
}
finally
{
    if (connection != null)
    {
        // some error occurred, try to rollback and return connection to
pool
        Transaction.safeRollback(dbConn);
        dbConn = null;
    }
}

It is safer to use a finally block than a catch block. In some ugly cases,
you get errors and not exceptions, and they are not caught by
catch(exception). Also, the finally block works even if you return inside
the block.

I have also written some docs about this, but I have forgotten to commit it
:-(.

    Thomas


Jim Caserta <sm...@yahoo.com> schrieb am 10.04.2006 15:27:37:

> Thomas,
>
> I was reading through this thread and I wantwed to be
> sure what you are saying. Is the example below the way
> we should be handling transactions? Thanks!
>
>
> Connection dbConn = null;
> try {
>       dbConn = Transaction.begin(db2.torque.environment));
>
>       ////Do Stuff
>       //Commit the transaction (Transaction.commit, should
> release connection back to the pool
>       Transaction.commit(dbConn);
>       Transaction.safeRollback(dbConn);
>    }catch(TorqueException e){
>       try {
>          Transaction.rollback(dbConn);
>       } catch (TorqueException e1) {
>          Transaction.safeRollback(dbConn);
>       }
>       }finally {
>          if(!dbConn.isClosed()){
>             Torque.closeConnection(dbConn);
>          }
>       }
>
>
> --- Thomas Fischer <tf...@apache.org> wrote:
>
> > Using commits/rollbacks without explicitly startung
> > a connection may look
> > unclean but does not cause any problems in practice
> > (at least none known
> > to me). The problem described seems to be the other
> > way round: there is no
> > rollback/commit where should be one.
> >
> >    Thomas
> >
> > On Mon, 27 Mar 2006, Greg Monroe wrote:
> >
> > > I did a quick wander thru the Torque code and saw
> > one thing
> > > that did not look right to me.  Here's some
> > background first:
> > >
> > > All of the Torque Transaction handling is built on
> > the
> > > Transaction class. This is used primarily by the
> > BasePeer
> > > methods like doUpdate(Criteria) and the like.
> > >
> > > These methods are the ones that automatically wrap
> > the
> > > DB actions as a transaction with rollback.
> > >
> > > The first thing that didn't look right to me was
> > that the
> > > Transaction.beginOptional(dbName, useTransaction)
> > method
> > > is called with the useTransaction arg set to the
> > value of
> > > criteria.isUseTransation().  This value is set to
> > false by
> > > default.
> > >
> > > So, it seems that if you don't set this explicitly
> > on your
> > > Criteria, you are not using really using
> > transactions but
> > > you still have the Transaction try/catch code with
> > commits and
> > > rollbacks.
> > >
> > > Shouldn't the default for isUseTransactions() be
> > true and/or
> > > the code handle the false condition without
> > calling the
> > > extra transaction methods?
> > >
> > >
> > >> -----Original Message-----
> > >> From: vivek sar [mailto:vivextra@gmail.com]
> > >> Sent: Saturday, March 25, 2006 4:44 AM
> > >>
> > >> Thanks Thomas for detailed explanation. I haven't
> > dig into
> > >> the Torque or dbcp code to tell exactly where the
> > fault lies.
> > >> The way I understand is that the db starts the
> > transaction on
> > >> your behalf if you don't start one. In case that
> > transaction
> > >> fails it will try to rollback. The problem I've
> > stated is
> > >> while the transaction is rolling back the same
> > connection is
> > >> somehow being used by other query and that's
> > causing the
> > >> "ORA-01453" and hanging of the connection.
> > >>
> > >>  I would think it's a problem with dbcp if not
> > torque as dbcp
> > >> is the one that handles the connection pool. I
> > couldn't find
> > >> much on the dbcp commons mailing-archiving list,
> > but found
> > >> tons of similar problems reported by torque
> > users, so I think
> > >> most of the people do assume it's a Torque
> > problem or
> > >> somewhere related to it.
> > >>
> > >>  Yes, if I do handle the transaction myself I
> > don't get into
> > >> this issue, but still the connection pool should
> > handle the
> > >> transactions/connections gracefully if it's
> > starting one on
> > >> your behalf.
> > >>
> > >>  I've the autocommit turned on (by default), so
> > it shouldn't
> > >> be problem with that either.
> > >>
> > >> I am still waiting for the right answer where
> > exactly the
> > >> problem lies -
> > >> 1) How do I get ORA-01453 if I am not starting
> > the transaction myself
> > >> 2) Why the connection hangs after the ORA-01453
> > >>
> > >> Thanks,
> > >> -vivek
> > >>
> > >
> > > Duke CE Privacy Statement
> > > Please be advised that this e-mail and any files
> > transmitted with it are confidential communication
> > or may otherwise be privileged or confidential and
> > are intended solely for the individual or entity to
> > whom they are addressed.  If you are not the
> > intended recipient you may not rely on the contents
> > of this email or any attachments, and we ask that
> > you  please not read, copy or retransmit this
> > communication, but reply to the sender and destroy
> > the email, its contents, and all copies thereof
> > immediately.  Any unauthorized dissemination,
> > distribution or copying of this communication is
> > strictly prohibited.
> > >
> > >
> > >
> > >
> >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > torque-user-unsubscribe@db.apache.org
> > > For additional commands, e-mail:
> > torque-user-help@db.apache.org
> > >
> > >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > torque-user-unsubscribe@db.apache.org
> > For additional commands, e-mail:
> > torque-user-help@db.apache.org
> >
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org