ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From janne mattila <jans...@luukku.com>
Subject Re: TransactionManager config for simultaneous EXTERNAL and JDBC transactions
Date Tue, 05 Jun 2007 13:26:18 GMT
Basically this means then that I need to ensure that methods that should cause rollback throw
an exception which gets thrown from the EJB (and this causes rollback for the EJB transaction).

"iBatis in Action" mentions how you can switch from local to global transactions and still
use the same code without modifications. Well, this is not exactly true then, or at least
you need to ensure that you don't have code which causes rollback when using local transactions
(by calling endTransaction without calling commitTransaction) without throwing exceptions,
as this would not cause a rollback when using a global (EJB) transaction.

as in, following code would cause problems:

daoManager.startTransaction;
try {
  someDao.doSomeUpdate();
  int result = someDao.selectSomeData();
  if (result = 42) {
    // everything is fine, commit
    daoManager.commitTransaction();
  } else {
    // wrong value, need to rollback (no exception)
  }
} finally {
  daoManager.endTransaction;
}



Jeff Butler kirjoitti 05.06.2007 kello 15:32:
> When using EXTERNAL transaction manager the start, end, and commit
>  methods
> do nothing.  It is expected that the EXTERNAL manager is dealing with
> commit.  EXTERNAL is used with EJB container managed transactions
>  where the
> EJB conteiner handles all transactions.
> 
> At the risk of speaking heresy...why don't you have a stateless
>  session EJB
> facade that handles transactions?  The JSP/Action tier can easily
>  call the
> EJB methods.  If you want to have a different EJB layer for other
>  clients,
> that layer can easily propogate it's transaction to the EJB facade. 
>  Simple!
> 
> Or, if you've drunk the Spring kool-aid, you can use Spring to inject a
> transaction manager into the iBATIS config differently for different
> clients.
> 
> Jeff Butler
> 
> 
> 
> On 6/5/07, janne mattila <jansu76@luukku.com> wrote:
> >
> > Follow-up question: what happens when EXTERNAL transaction manager is
> > used, transaction is started with DaoManager.startTransaction, and
> > transaction is ended using DaoManager.endTransaction and transaction has
> > _not_ been committed using DaoManager.commitTransaction?
> >
> > Does this cause the external transaction to be rolled back (like it would
> > cause a JDBC transaction to be rolled back)?
> >
> > janne mattila kirjoitti 05.06.2007 kello 15:10:
> > > I am implementing a system which has a number of iBatis DAOs that
> > >  are used
> > > both by EJB clients and basic web application code.
> > >
> > > Architecture will be like
> > >
> > > (EJB)
> > > (JSPs/Actions etc)
> > >   |
> > >   |
> > >   |
> > > (business logic layer)
> > >   |
> > >   |
> > >   |
> > > (DAOs)
> > >
> > > EJBs use container managed transactions, and hence I should use EXTERNAL
> > > transaction manager.
> > >
> > > Web application code should use basic iBatis JNDI/SIMPLE transaction
> > > manager and transactions are demarcated on the business logic layer
> > >  using
> > > daoManager.startTransaction() etc.
> > >
> > > Both "business logic clients" (EJB & web app code) should use the same
> > > business logic methods (which use the same DAO code). I understand I can
> > > use the same business logic layer for both, since for example
> > > daoManager.commitTransaction() will not do anything if EXTERNAL
> > > transactions are configured?
> > >
> > > How should iBatis configuration be done??? Do I have to have separate
> > > dao1.xml and dao2.xml files and build separate DaoManager instances
> > >  for the
> > > EJB clients and the web app clients?
> > >
> > > Anything specific that I need to worry about using this approach?
> > >
> > > ...................................................................
> > > Luukku Plus paketilla pääset eroon tila- ja turvallisuusongelmista.
> > > Hanki Luukku Plus ja helpotat elämääsi. http://www.mtv3.fi/luukku
> > >
> >
> >
> > ...................................................................
> > Luukku Plus paketilla pääset eroon tila- ja turvallisuusongelmista.
> > Hanki Luukku Plus ja helpotat elämääsi. http://www.mtv3.fi/luukku
> >
> >


...................................................................
Luukku Plus paketilla pääset eroon tila- ja turvallisuusongelmista.
Hanki Luukku Plus ja helpotat elämääsi. http://www.mtv3.fi/luukku


Mime
View raw message