I've been using a pretty simple setup where a StatelessSession bean coordinates calls
to various DAO's to perform inserts and updates. I began noticing a while back that
many of my apps connections leave open transactions and am begining to wonder if I've
misunderstood something about the transactional manager and the way it handles its
exception handling.
I use JBossAS 4.0.2 on a W2K machine running against W2K SQLServer.
The session beans are setup to utilize the containers CMT.
| public void updatePersonInfoInTemp(int personId, ArrayList tests)throws
GeneralFailureException{
| RegistrationDAO dao = new RegistrationDAO();
| try {
| TestInfo test = null;
| for(int i=0; i<tests.size();i++){
| test = (TestInfo)tests.get(i);
| dao.updatePersonInfoInTemp(test.getSessionId(), test.getTestCode(), personId);
| }
| } catch (SQLException e) {
| // context.setRollbackOnly(); // is this needed?
| throw new GeneralFailureException(e.getMessage());
| } catch (NamingException e) {
| // context.setRollbackOnly(); // is this needed?
| throw new GeneralFailureException(e.getMessage());
| }
| }
|
Exception classes:
| public class GeneralFailureException extends EventException{
|
| private Throwable t;
|
| public GeneralFailureException(String s) {
| super(s);
| }
|
| public GeneralFailureException(String s, Throwable t) {
| super(s);
| this.t = t;
| }
|
| public String getThrowable() {
| return ("Received throwable with Message: "+ t.getMessage());
| }
| }
| public class EventException extends Exception
| implements java.io.Serializable {
|
| public EventException() {}
|
| public EventException(String str) {
| super(str);
| }
| }
|
The DAO's don't do anything special except throw the indicated error when
encountered, such as:
| public void updatePersonInfoInTemp(int sessionId, String testCode, int
personId)throws SQLException, NamingException{
| logger.debug("entering updatePersonInfoInTemp");
| Connection con = null;
| PreparedStatement ps = null;
| ResultSet rs = null;
| try {
| con = getConnection(AppHelper.SC_DEFAULT_DS_CON);
| try {
| ps = con.prepareStatement(
| "UPDATE TempTest SET PersonID = ? " +
| "WHERE SessionID = ? AND TestCode = ?");
|
| int count = 1;
| ps.setInt(count++, personId);
| ps.setInt(count++, sessionId);
| ps.setString(count++, testCode);
|
| ps.executeUpdate();
| } catch (SQLException ex) {
| logger.error(ex);
| throw ex;
| }
| } finally {
| AppHelper.closeResultSet(rs);
| AppHelper.closeStatement(ps);
| AppHelper.releaseConnection(con);
| }
| logger.debug("leaving updatePersonInfoInTemp");
| }
|
Is there something that I'm doing that would cause transactions to be left open?
Thanks for any help.
Graham
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3977969#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...