ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Debasish Dutta Roy" <debasish.dutta...@gmail.com>
Subject Re: URGENT - Cannot get Transaction Management to work with iBATIS !!!
Date Wed, 28 Jun 2006 14:13:14 GMT
Damn!!! So much for the details huh :)

Oracle 9i.

JDBC Driver : orajdbc-9.2.0.jar

On 6/28/06, Richard Yee <ryee@cruzio.com> wrote:
>
> Which database are you using?
>
> -Richard
>
>
> Debasish Dutta Roy wrote:
> > My Environment
> >
> > Server: Tomcat 5
> > JDK: 1.4.2
> >
> > Datasource
> > ---------------
> > Defined in Tomcat as a JNDI resource. Mentioned in web.xml as a
> > resource ref.
> >
> > Application design
> > -------------------------
> > Web layer : Struts action classes
> >
> > Middle layer: Normal business delegate classes. Action classes does
> >
> >     CustomerDelegate delegate = new CustomerDelegate();
> >     long empId = delegate.addCustomer(customerVO);
> >
> > Inside the delegate class method there are multiple inserts into the
> > database.
> >
> > Typical delegate add method:
> >
> >     try {
> >
> >         CustomerDAO customerDAO =
> > this.daoManager.getDao(CustomerDAO.class );
> >         this.daoManager.startTransaction();
> >         long customerId = customerDAO.addCustomerSummary(argParam);
> > //first insert
> >         long lineItemId = customerDAO.addCustomerLineItem(argParam,
> > customerId); //second insert
> >         this.daoManager.commitTransaction();
> >     } catch (MyException me) {
> >         logger.error();
> >      } finally {
> >         this.daoManager.endTransaction(); //suppose to commit if any
> > of the above insert fails
> >     }
> >
> > DAO classes
> >
> >     CustomerDAO is a plain interface containing only the method
> > signatures.
> >
> >     public interface CustomerDAO
> >
> > DAO Implementation
> >
> >     There are several dao implementations of the CustomerDAO
> > interface. SQLMap interface is one of them
> >
> > SQLMap implementation
> >
> >     1. SqlMapCustomerDAOImpl extends BaseSqlMapDAO implements
> CustomerDAO
> >     2. There is not transaction management code in this class. It
> > simply uses sqlMapClient to do the work.
> >
> >     Typical code sample
> >
> >         try {
> >             SqlMapClient mapClient =
> > MySqlConfigurator.getSqlMapClientInstance();
> >             customerId =
> > (Long)mapClient.insert("insertPrimaryCustomer", argCustomer);
> >         } catch (SQLException sqle) {
> >             logger.error("Failed to add", sqle);
> >             throw new DAOException(sqle.getMessage()); // this is not
> > a iBATIS DaoException
> >         }
> >
> >
> > BaseSqlMapDAO
> >
> >     This extends SqlMapDaoTemplate
> >
> >
> > MySqlConfigurator
> >
> >         private static SqlMapClient sqlMap;
> >
> >     static {
> >         try {
> >             String resource = "xml/sql- map-config.xml";
> >             Reader reader = Resources.getResourceAsReader(resource);
> >             sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
> >         } catch (Exception e) {
> >             e.printStackTrace ();
> >         }
> >     }
> >
> >
> > iBATIS configuration
> > ----------------
> > 1. I have a dao.xml. Important configuration details are as follows:
> >
> >     <context>
> >         <transactionManager type="SQLMAP">
> >             <property name="SqlMapConfigResource"
> > value="xml/sql-map-config.xml"/>
> >         </transactionManager>
> >
> >         <!-- DAO declarations -->
> >         <dao interface=" com.myproject.db.dao.CustomerDAO"
> >
> >  implementation="com.myproject.db.dao.sqlmap.SqlMapCustomerDAOImpl"/>
> >     </context>
> >
> > There is only one context. All the DAOs are defined inside one context
> > tag.
> >
> > 2. There is a sql-map-config.xml. Important configuration details are
> > as follows:
> >
> >     <sqlMapConfig>
> >     <properties resource="xml/SqlMapConfig.properties"/>
> >
> >     <transactionManager type="JDBC" commitRequired="true">
> >         <property name="DefaultAutoCommit" value="false"/>
> >         <property name="SetAutoCommitAllowed" value="false"/>
> >         <dataSource type="JNDI">
> >             <property name="DataSource" value="${MyJndiDatasource}"/>
> >         </dataSource>
> >     </transactionManager>
> >
> >     <sqlMap resource="xml/Customer.xml"/>
> >     <!-- And many others -->
> >
> > </sqlMapConfig>
> >
> >
> > Problem: Now as mentioned above I have 2 inserts. And if the second
> > one fails, the first one is not rolled back. I have tried all possible
> > things. Just does not work.
> >
>
>

Mime
View raw message