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.


Reply via email to