You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Hoyoung Hwang <hw...@gmail.com> on 2006/07/04 03:19:06 UTC

how can i use mutiple transction in thread?

i can't use muitple transaction.
how can i use mutiple transction?

i don't use daoManager. just using SqlMap.

example.

sqlmapclient.startTransaction();
sqlmapclient.insert("table.insert",table);
newTrans = sqlmapclient.openSession();
newTrans.startTransaction();
newTrans.insert("logtable.insert",logtable);
newTrans.commitTransaction();
sqlmapclient.delete("table.delete",null);
sqlmapclient.commitTransaction();

please let me know.

Re: how can i use mutiple transction in thread?

Posted by Jeff Butler <je...@gmail.com>.
Hi Clinton,

Are you sure about this?  The session is stored as ThreadLocal in
SqlMapClientImpl - there is no provision I can see for having more than one
open session.  Was that the original intent?

Jeff Butler


On 7/6/06, Clinton Begin <cl...@gmail.com> wrote:
>
> That might be a bug then.  Very odd.  That's the whole point of
> sessions...
>
> Feel free to submit a JIRA bug for it.
>
> Cheers,
>
> Clinton
>
>
> On 7/6/06, Hoyoung Hwang <hw...@gmail.com> wrote:
> >
> >  thanks, but that doesn't work.
> > i try below code.
> >
> >   SqlMapSession sess1 = SqlMapClientBase.openSession();
> >   SqlMapSession sess2 = SqlMapClientBase.openSession();
> >   if(sess1 == sess2) System.out.println("equal");    // <-- this code
> > return true.
> >   sess1.startTransaction();
> >   sess2.startTransaction(); // <-- error occure : TransactionManager
> > could not start a new transaction.  A transaction is already started.
> >   sess1.update("table1.update", table1Bean);
> >   sess2.update("table2.update", table2Bean);
> >   sess2.commitTransaction();
> >   sess2.endTransaction();
> >   sess1.commitTransaction();
> >   sess1.endTransaction();
> >
> > i want to use transaction, both of sessions.
> > and each session is not depdent to another session.
> >
> >
> >
> >
> > On 7/6/06, Clinton Begin <clinton.begin@gmail.com > wrote:
> > >
> > >
> > > Use openSession() twice...don't call .startTransaction directly on the
> > > SqlMapClient for either of them.
> > >
> > > Cheers,
> > >
> > > Clinton
> > >
> > >
> > >
> > > On 7/5/06, Hoyoung Hwang <hw...@gmail.com> wrote:
> > > >
> > > >  thans for your answer.
> > > >
> > > > but, i need not nested transaction.
> > > > (yes, if ibatis support that, i use that model.)
> > > >
> > > > i want to use muliple transaction (or connection) model.
> > > >
> > > > i need second transaction is commit immediately.
> > > > not dependent first transaction.
> > > >
> > > > in first transaction is processing,
> > > > another transaction can commit at same thread.
> > > >
> > > > in example--------------
> > > >  sqlmapclient.startTransaction();         //first transaction start
> > > >  sqlmapclient.insert("table.insert",table);
> > > > newTrans = sqlmapclient.openSession();
> > > >  newTrans.startTransaction();              //second transaction
> > > > start , but it is not work.
> > > >  newTrans.insert("logtable.insert",logtable);
> > > > newTrans.commitTransaction();
> > > > sqlmapclient.delete("table.delete",null);
> > > > sqlmapclient.commitTransaction();
> > > >
> > > >
> > > > On 7/6/06, Clinton Begin <clinton.begin@gmail.com > wrote:
> > > > >
> > > > >
> > > > > Regardless....the JDBC driver and/or database likely doesn't
> > > > > support this.  Few databases do.  I think Sybase (and SQL Server?) support
> > > > > nested transactions, but they're not recommended.  Oracle supports
> > > > > savepoints, which is somewhat cleaner...but ideally you should probably just
> > > > > simplify your transaction model so that this isn't required.
> > > > >
> > > > >
> > > > > Clinton
> > > > >
> > > > >
> > > > >
> > > > > On 7/5/06, Jeff Butler <jeffgbutler@gmail.com > wrote:
> > > > > >
> > > > > >  iBATIS does not support nested transactions like this.
> > > > > >
> > > > > > Jeff Butler
> > > > > >
> > > > > >
> > > > > >  On 7/3/06, Hoyoung Hwang <hw...@gmail.com> wrote:
> > > > > > >
> > > > > > >  i can't use muitple transaction.
> > > > > > > how can i use mutiple transction?
> > > > > > >
> > > > > > > i don't use daoManager. just using SqlMap.
> > > > > > >
> > > > > > > example.
> > > > > > >
> > > > > > > sqlmapclient.startTransaction();
> > > > > > > sqlmapclient.insert("table.insert",table);
> > > > > > > newTrans = sqlmapclient.openSession();
> > > > > > > newTrans.startTransaction();
> > > > > > > newTrans.insert("logtable.insert",logtable);
> > > > > > > newTrans.commitTransaction();
> > > > > > > sqlmapclient.delete("table.delete",null);
> > > > > > > sqlmapclient.commitTransaction();
> > > > > > >
> > > > > > > please let me know.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>

Re: how can i use mutiple transction in thread?

Posted by Clinton Begin <cl...@gmail.com>.
That might be a bug then.  Very odd.  That's the whole point of sessions...

Feel free to submit a JIRA bug for it.

Cheers,
Clinton

On 7/6/06, Hoyoung Hwang <hw...@gmail.com> wrote:
>
> thanks, but that doesn't work.
> i try below code.
>
>   SqlMapSession sess1 = SqlMapClientBase.openSession();
>   SqlMapSession sess2 = SqlMapClientBase.openSession();
>   if(sess1 == sess2) System.out.println("equal");    // <-- this code
> return true.
>   sess1.startTransaction();
>   sess2.startTransaction(); // <-- error occure : TransactionManager could
> not start a new transaction.  A transaction is already started.
>   sess1.update("table1.update", table1Bean);
>   sess2.update("table2.update", table2Bean);
>   sess2.commitTransaction();
>   sess2.endTransaction();
>   sess1.commitTransaction();
>   sess1.endTransaction();
>
> i want to use transaction, both of sessions.
> and each session is not depdent to another session.
>
>
>
>
> On 7/6/06, Clinton Begin <cl...@gmail.com> wrote:
> >
> >
> > Use openSession() twice...don't call .startTransaction directly on the
> > SqlMapClient for either of them.
> >
> > Cheers,
> >
> > Clinton
> >
> >
> >
> > On 7/5/06, Hoyoung Hwang <hw...@gmail.com> wrote:
> > >
> > >  thans for your answer.
> > >
> > > but, i need not nested transaction.
> > > (yes, if ibatis support that, i use that model.)
> > >
> > > i want to use muliple transaction (or connection) model.
> > >
> > > i need second transaction is commit immediately.
> > > not dependent first transaction.
> > >
> > > in first transaction is processing,
> > > another transaction can commit at same thread.
> > >
> > > in example--------------
> > >  sqlmapclient.startTransaction();         //first transaction start
> > >  sqlmapclient.insert("table.insert",table);
> > > newTrans = sqlmapclient.openSession();
> > >  newTrans.startTransaction();              //second transaction
> > > start , but it is not work.
> > >  newTrans.insert("logtable.insert",logtable);
> > > newTrans.commitTransaction();
> > > sqlmapclient.delete("table.delete",null);
> > > sqlmapclient.commitTransaction();
> > >
> > >
> > > On 7/6/06, Clinton Begin <clinton.begin@gmail.com > wrote:
> > > >
> > > >
> > > > Regardless....the JDBC driver and/or database likely doesn't support
> > > > this.  Few databases do.  I think Sybase (and SQL Server?) support nested
> > > > transactions, but they're not recommended.  Oracle supports savepoints,
> > > > which is somewhat cleaner...but ideally you should probably just simplify
> > > > your transaction model so that this isn't required.
> > > >
> > > >
> > > > Clinton
> > > >
> > > >
> > > >
> > > > On 7/5/06, Jeff Butler <jeffgbutler@gmail.com > wrote:
> > > > >
> > > > >  iBATIS does not support nested transactions like this.
> > > > >
> > > > > Jeff Butler
> > > > >
> > > > >
> > > > >  On 7/3/06, Hoyoung Hwang <hw...@gmail.com> wrote:
> > > > > >
> > > > > >  i can't use muitple transaction.
> > > > > > how can i use mutiple transction?
> > > > > >
> > > > > > i don't use daoManager. just using SqlMap.
> > > > > >
> > > > > > example.
> > > > > >
> > > > > > sqlmapclient.startTransaction();
> > > > > > sqlmapclient.insert("table.insert",table);
> > > > > > newTrans = sqlmapclient.openSession();
> > > > > > newTrans.startTransaction();
> > > > > > newTrans.insert("logtable.insert",logtable);
> > > > > > newTrans.commitTransaction();
> > > > > > sqlmapclient.delete("table.delete",null);
> > > > > > sqlmapclient.commitTransaction();
> > > > > >
> > > > > > please let me know.
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > >
> >
>

Re: how can i use mutiple transction in thread?

Posted by Hoyoung Hwang <hw...@gmail.com>.
thanks, but that doesn't work.
i try below code.

  SqlMapSession sess1 = SqlMapClientBase.openSession();
  SqlMapSession sess2 = SqlMapClientBase.openSession();
  if(sess1 == sess2) System.out.println("equal");    // <-- this code
return true.
  sess1.startTransaction();
  sess2.startTransaction(); // <-- error occure : TransactionManager could
not start a new transaction.  A transaction is already started.
  sess1.update("table1.update", table1Bean);
  sess2.update("table2.update", table2Bean);
  sess2.commitTransaction();
  sess2.endTransaction();
  sess1.commitTransaction();
  sess1.endTransaction();

i want to use transaction, both of sessions.
and each session is not depdent to another session.




On 7/6/06, Clinton Begin <cl...@gmail.com> wrote:
>
>
> Use openSession() twice...don't call .startTransaction directly on the
> SqlMapClient for either of them.
>
> Cheers,
>
> Clinton
>
>
>
> On 7/5/06, Hoyoung Hwang <hw...@gmail.com> wrote:
> >
> >  thans for your answer.
> >
> > but, i need not nested transaction.
> > (yes, if ibatis support that, i use that model.)
> >
> > i want to use muliple transaction (or connection) model.
> >
> > i need second transaction is commit immediately.
> > not dependent first transaction.
> >
> > in first transaction is processing,
> > another transaction can commit at same thread.
> >
> > in example--------------
> >  sqlmapclient.startTransaction();         //first transaction start
> >  sqlmapclient.insert("table.insert",table);
> > newTrans = sqlmapclient.openSession();
> >  newTrans.startTransaction();              //second transaction start ,
> > but it is not work.
> >  newTrans.insert("logtable.insert",logtable);
> > newTrans.commitTransaction();
> > sqlmapclient.delete("table.delete",null);
> > sqlmapclient.commitTransaction();
> >
> >
> > On 7/6/06, Clinton Begin <clinton.begin@gmail.com > wrote:
> > >
> > >
> > > Regardless....the JDBC driver and/or database likely doesn't support
> > > this.  Few databases do.  I think Sybase (and SQL Server?) support nested
> > > transactions, but they're not recommended.  Oracle supports savepoints,
> > > which is somewhat cleaner...but ideally you should probably just simplify
> > > your transaction model so that this isn't required.
> > >
> > >
> > > Clinton
> > >
> > >
> > >
> > > On 7/5/06, Jeff Butler <jeffgbutler@gmail.com > wrote:
> > > >
> > > >  iBATIS does not support nested transactions like this.
> > > >
> > > > Jeff Butler
> > > >
> > > >
> > > >  On 7/3/06, Hoyoung Hwang <hw...@gmail.com> wrote:
> > > > >
> > > > >  i can't use muitple transaction.
> > > > > how can i use mutiple transction?
> > > > >
> > > > > i don't use daoManager. just using SqlMap.
> > > > >
> > > > > example.
> > > > >
> > > > > sqlmapclient.startTransaction();
> > > > > sqlmapclient.insert("table.insert",table);
> > > > > newTrans = sqlmapclient.openSession();
> > > > > newTrans.startTransaction();
> > > > > newTrans.insert("logtable.insert",logtable);
> > > > > newTrans.commitTransaction();
> > > > > sqlmapclient.delete("table.delete",null);
> > > > > sqlmapclient.commitTransaction();
> > > > >
> > > > > please let me know.
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> >
>

Re: how can i use mutiple transction in thread?

Posted by Clinton Begin <cl...@gmail.com>.
Use openSession() twice...don't call .startTransaction directly on the
SqlMapClient for either of them.

Cheers,
Clinton


On 7/5/06, Hoyoung Hwang <hw...@gmail.com> wrote:
>
> thans for your answer.
>
> but, i need not nested transaction.
> (yes, if ibatis support that, i use that model.)
>
> i want to use muliple transaction (or connection) model.
>
> i need second transaction is commit immediately.
> not dependent first transaction.
>
> in first transaction is processing,
> another transaction can commit at same thread.
>
> in example--------------
>  sqlmapclient.startTransaction();         //first transaction start
> sqlmapclient.insert("table.insert",table);
> newTrans = sqlmapclient.openSession();
> newTrans.startTransaction();              //second transaction start ,
> but it is not work.
> newTrans.insert("logtable.insert",logtable);
> newTrans.commitTransaction();
> sqlmapclient.delete("table.delete",null);
> sqlmapclient.commitTransaction();
>
>
> On 7/6/06, Clinton Begin <clinton.begin@gmail.com > wrote:
> >
> >
> > Regardless....the JDBC driver and/or database likely doesn't support
> > this.  Few databases do.  I think Sybase (and SQL Server?) support nested
> > transactions, but they're not recommended.  Oracle supports savepoints,
> > which is somewhat cleaner...but ideally you should probably just simplify
> > your transaction model so that this isn't required.
> >
> >
> > Clinton
> >
> >
> >
> > On 7/5/06, Jeff Butler <jeffgbutler@gmail.com > wrote:
> > >
> > >  iBATIS does not support nested transactions like this.
> > >
> > > Jeff Butler
> > >
> > >
> > >  On 7/3/06, Hoyoung Hwang <hw...@gmail.com> wrote:
> > > >
> > > >  i can't use muitple transaction.
> > > > how can i use mutiple transction?
> > > >
> > > > i don't use daoManager. just using SqlMap.
> > > >
> > > > example.
> > > >
> > > > sqlmapclient.startTransaction();
> > > > sqlmapclient.insert("table.insert",table);
> > > > newTrans = sqlmapclient.openSession();
> > > > newTrans.startTransaction();
> > > > newTrans.insert("logtable.insert",logtable);
> > > > newTrans.commitTransaction();
> > > > sqlmapclient.delete("table.delete",null);
> > > > sqlmapclient.commitTransaction();
> > > >
> > > > please let me know.
> > > >
> > > >
> > > >
> > >
> > >
> >
>

Re: how can i use mutiple transction in thread?

Posted by Hoyoung Hwang <hw...@gmail.com>.
thans for your answer.

but, i need not nested transaction.
(yes, if ibatis support that, i use that model.)

i want to use muliple transaction (or connection) model.

i need second transaction is commit immediately.
not dependent first transaction.

in first transaction is processing,
another transaction can commit at same thread.

in example--------------
 sqlmapclient.startTransaction();         //first transaction start
sqlmapclient.insert("table.insert",table);
newTrans = sqlmapclient.openSession();
newTrans.startTransaction();              //second transaction start ,
but it is not work.
newTrans.insert("logtable.insert",logtable);
newTrans.commitTransaction();
sqlmapclient.delete("table.delete",null);
sqlmapclient.commitTransaction();


On 7/6/06, Clinton Begin <cl...@gmail.com> wrote:
>
>
> Regardless....the JDBC driver and/or database likely doesn't support
> this.  Few databases do.  I think Sybase (and SQL Server?) support nested
> transactions, but they're not recommended.  Oracle supports savepoints,
> which is somewhat cleaner...but ideally you should probably just simplify
> your transaction model so that this isn't required.
>
>
> Clinton
>
>
>
> On 7/5/06, Jeff Butler <je...@gmail.com> wrote:
> >
> >  iBATIS does not support nested transactions like this.
> >
> > Jeff Butler
> >
> >
> >  On 7/3/06, Hoyoung Hwang <hw...@gmail.com> wrote:
> > >
> > >  i can't use muitple transaction.
> > > how can i use mutiple transction?
> > >
> > > i don't use daoManager. just using SqlMap.
> > >
> > > example.
> > >
> > > sqlmapclient.startTransaction();
> > > sqlmapclient.insert("table.insert",table);
> > > newTrans = sqlmapclient.openSession();
> > > newTrans.startTransaction();
> > > newTrans.insert("logtable.insert",logtable);
> > > newTrans.commitTransaction();
> > > sqlmapclient.delete("table.delete",null);
> > > sqlmapclient.commitTransaction();
> > >
> > > please let me know.
> > >
> > >
> > >
> >
> >
>

Re: how can i use mutiple transction in thread?

Posted by Clinton Begin <cl...@gmail.com>.
Regardless....the JDBC driver and/or database likely doesn't support this.
Few databases do.  I think Sybase (and SQL Server?) support nested
transactions, but they're not recommended.  Oracle supports savepoints,
which is somewhat cleaner...but ideally you should probably just simplify
your transaction model so that this isn't required.

Clinton


On 7/5/06, Jeff Butler <je...@gmail.com> wrote:
>
> iBATIS does not support nested transactions like this.
>
> Jeff Butler
>
>
> On 7/3/06, Hoyoung Hwang <hw...@gmail.com> wrote:
> >
> >  i can't use muitple transaction.
> > how can i use mutiple transction?
> >
> > i don't use daoManager. just using SqlMap.
> >
> > example.
> >
> > sqlmapclient.startTransaction();
> > sqlmapclient.insert("table.insert",table);
> > newTrans = sqlmapclient.openSession();
> > newTrans.startTransaction();
> > newTrans.insert("logtable.insert",logtable);
> > newTrans.commitTransaction();
> > sqlmapclient.delete("table.delete",null);
> > sqlmapclient.commitTransaction();
> >
> > please let me know.
> >
> >
> >
>
>

Re: how can i use mutiple transction in thread?

Posted by Jeff Butler <je...@gmail.com>.
iBATIS does not support nested transactions like this.

Jeff Butler


On 7/3/06, Hoyoung Hwang <hw...@gmail.com> wrote:
>
>  i can't use muitple transaction.
> how can i use mutiple transction?
>
> i don't use daoManager. just using SqlMap.
>
> example.
>
> sqlmapclient.startTransaction();
> sqlmapclient.insert("table.insert",table);
> newTrans = sqlmapclient.openSession();
> newTrans.startTransaction();
> newTrans.insert("logtable.insert",logtable);
> newTrans.commitTransaction();
> sqlmapclient.delete("table.delete",null);
> sqlmapclient.commitTransaction();
>
> please let me know.
>
>
>