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 Thu, 29 Jun 2006 20:41:05 GMT
Thank Jeff!!!

That was exactly what it was.

On 6/28/06, Jeff Butler <jeffgbutler@gmail.com> wrote:
>
> Hmmm....
>
> I think the issue might be in your DAO implemetation class.  It looks like
> you are re-initializing the SqlMapConfig in this class (calling the
> MySqlConfigurator) rather than using the sqlmap client that the DAO manager
> has built for you.  This may be causing some strange transactional behavior.
>
>
> If you are using SqlMapDaoTemplate, as you say you are, then the DAO
> methods can be very simple:
>
> Long addCustomerSummary(SomeClass argCustomer) {
>    return (Long) insert("insertPrimaryCustomer", argCustomer);
> }
>
> Jeff Butler
>
>
>
>
>
>
> On 6/28/06, Debasish Dutta Roy <debasish.duttaroy@gmail.com> wrote:
> >
> > 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