I was using oc4j for development of a weba application involving JSP, servlets and JDBC (dayabase: oracle 11gr2). Had used built in transaction manager and commits and rollbacks used to work fine.
However, due to licensing we are now supposed to move the code to a free server like tomcat. I have implemented JOTM as the transaction manager in tomcat following the steps in this post:
http://codepitbull.wordpress.com/2011/07/08/tomcat-7-with-full-jta/
The following is the configuration in %CATALINA_HOME%/conf/context.xml
<Resource name="jdbc/ticketds"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
validationQuery="SELECT 1"
maxActive="30"
minIdle="2"
maxWait="10000"
initialSize="10"
defaultAutoCommit="false"
username="xxxx"
password="xxxxx"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@//xxxxx.xxxx.com:iiii/xyz"/>
<Resource name="jdbc/taskds"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
validationQuery="SELECT 1"
maxActive="30"
minIdle="2"
maxWait="10000"
initialSize="10"
defaultAutoCommit="false"
username="apps"
password="few1idna"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@//xxxxx.xxxx.com:iiii/xyz"/>
<Transaction factory="org.objectweb.jotm.UserTransactionFactory"
jotm.timeout="600"/>
The web.xml is configured to mention the datasource in resource-refs like so:
<resource-ref>
<description>Ticket Datasource configuration</description>
<res-ref-name>jdbc/ticketds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>SR Datasource configuration</description>
<res-ref-name>jdbc/taskds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
However, when i try to perform rollbacks, it does not help. Here is a sample test code for rollback that i am using for testing:
UserTransaction utx = DBUtil.getUserTransaction();
Connection conn = DBUtil.getConnection();
TicketMessageVO newTicket = null;
try {
utx.begin();
newTicket = new TicketDAO(conn).createTicket(ticket);
// testing only
if(1==1) throw new Exception("Testing transaction rollback");
utx.commit();
logger.log(Level.INFO, "Ticket created successfully: " + ticket.getMessageId());
} catch (Throwable e) {
utx.rollback();
logger.log(Level.SEVERE, "Error in creating ticket: ", e);
throw new Exception(e);
} finally {
DBUtil.closeResources(null, null, conn);
}
return newTicket;
The same bit of code used to work perfectly with oc4j. Am i missing something in the configuration?
Thanks.
I recently run into the same issue and I solved it using JOTM's own datasource factory (org.objectweb.jotm.datasource.DataSourceFactory
) instead of Tomcat's. This is how your context.xml should look like:
<Resource name="jdbc/taskds"
auth="Container"
type="javax.sql.DataSource"
factory="org.objectweb.jotm.datasource.DataSourceFactory"
validationQuery="SELECT 1"
maxActive="30"
minIdle="2"
maxWait="10000"
initialSize="10"
defaultAutoCommit="false"
username="apps"
password="few1idna"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@//xxxxx.xxxx.com:iiii/xyz"/>
However, using JOTM this way causes Tomcat to hang during shutdown (maybe due to a non-daemon thread in Carol).