Thanks Marten. It was the same issue infact.
Actually this transaction manager works fine for a single datasource, but fails in case we have multiple datasources. I am using two sybase datasources installed on two different boxes. Here is the description of the problem:
The initiated transaction keeps hold of the first connection and substitutes it for every connection requested thereafter. Obviously the first connection will not work with any datasource but the one it is connected to. Thinking from transaction’s perspective it should have a reference to the first connection to rollback in case the query for second datasource fails. So the clever transaction is playing safe from its point of view. And thus I am not able to connect to the second datasource.
Both of the databse get updated if I don't use the transaction manager.
There should be some way to enable the request for the new connection instead of picking it up from the transactions cache reference.
Here is code that i am using to fire the queries from sql maps (I am using iBATIS with Spring).
Code:
private Object doInsert(String theSQL, TestData testData, String dataSource) throws DomainDataDAOException {
Connection conn = null;
SqlMapSession session = null;
try {
// dataSource will have different values for different datasources. Refer to handbook for more details.
DataSourceContextHolder.setDataSourceType(dataSource);
conn = getSqlMapClientTemplate().getSqlMapClient().getDataSource().getConnection();
session = getSqlMapClientTemplate().getSqlMapClient().openSession(conn);
return ((Object) session.insert(theSQL, testData));
} catch (SQLException exSQLException) {
throw new DomainDataDAOException("SQLException has occured while fetching the data.", exSQLException);
} catch (SqlMapException exSqlMapException) {
throw new DomainDataDAOException( "There seems to be a type mismatch for the columns in sqlmap"+
"and the model for the table.", exSqlMapException);
} catch (Exception ex) {
throw new DomainDataDAOException("Exception occured while fetching the data.", ex);
} finally {
DataSourceContextHolder.clearDataSourceType();
if (session != null)
session.close();
try {
if (conn != null)
conn.close();
} catch (SQLException exSQLException) {
throw new DomainDataDAOException(
"SQLException has occured while closing the database connection.",
exSQLException);
}
}
}
Could you please suggest the solution for this.
Thanks,
Ritwick