ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Akins, Greg" <gak...@amervideo.com>
Subject RE: SqlMap transactions
Date Fri, 18 Feb 2005 16:40:18 GMT
Thanks.  BTW, this code should fail.  It's the exception throws from
sqlmap.endTransaction() that is worrying me.

Here is the method
    public int update(HoldAvp avp) throws SQLException  {
        log.info("*** GAK *** apvId = " + avp.getId()) ; 
        SqlMapClient sqlmap = this.getSqlMap() ;
        int retVal = 0 ;
        try {
            sqlmap.startTransaction() ;
            retVal = sqlmap.update("updateAvp", avp);
            log.info("**** GAK **** Updated " + retVal + " records in
Avp ") ; 
            //for each ware in Avp, do updateWare...
            int waresUpdated = 0 ;
            log.info("*** GAK *** Handling " + avp.getWares().size() + "
wares");
            List list = avp.getWares(); 
            for (int i=0;i<list.size();i++){
                Ware ware = null ; 
                if (list.get(i) instanceof WareTmp) {
                    ware = (WareTmp)list.get(i) ; 
                }
                else {
                    ware = (Ware)list.get(i) ;
                }
                LocalWareDAO wdao = new LocalWareDAO() ;  
                if (ware.getId()==null) {
                    ware.setAvpId(avp.getId()) ; 
                    log.info("*** GAK *** Inserting ware " +
ware.toString()) ; 
                    Integer wareKey = null ;
                    try {
                        wareKey = (Integer)sqlmap.insert("insertWare",
ware);
                    } catch (Exception e) {
                        // @todo Auto-generated catch block
                        e.printStackTrace();
                    }
                    ware.setId(wareKey) ;
                    log.info("*** GAK *** Handled ware " + ware.getId())
; 
                    waresUpdated++ ; 
                }
                else {
                    log.info("*** GAK *** Updating ware " +
ware.getLaserId()) ;
                    ware = LocalWareDAO.translateWareTmp(ware) ; 
                    sqlmap.update("updateWare", ware) ;
                    waresUpdated++ ;
                }
            }
            retVal += waresUpdated ;
            try {
                sqlmap.commitTransaction() ;
            } catch (SQLException e1) {
                log.warn("*** GAK *** Commit Transaction failed,
throwing to endTransaction()");
            }
        } catch (SQLException e) {
            try {
                sqlmap.endTransaction() ;
                
                throw e ; 
            } catch (SQLException e1) {
                log.warn("*** GAK *** End Transaction Failed " +
e1.getMessage()) ;
                e1.printStackTrace() ;
                throw e1 ; 
            } 
        }

        return retVal ; 
    }

The logs and stack traces  look like:
2005-02-18 11:36:00,163 INFO  [com.amervideo.ehold.dao.LocalAvpDAO] ***
GAK *** apvId = null
2005-02-18 11:36:00,163 DEBUG [com.ibatis.common.jdbc.SimpleDataSource]
Checked out connection 1117233 from pool.
2005-02-18 11:36:00,163 DEBUG [java.sql.Connection] {conn-100026}
Connection
2005-02-18 11:36:00,179 DEBUG [com.ibatis.common.jdbc.SimpleDataSource]
Returned connection 1117233 to pool.
com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in com/amervideo/ehold/sql/local/HoldAvpSQL.xml.

--- The error occurred while applying a parameter map.  
--- Check the updateAvp-InlineParameterMap.  
--- Check the parameter mapping for the 'id' property.  
--- Cause: java.sql.SQLException: Invalid column type
Caused by: java.sql.SQLException: Invalid column type
2005-02-18 11:36:00,179 WARN  [com.amervideo.ehold.dao.LocalAvpDAO] ***
GAK *** End Transaction Failed   
--- The error occurred in com/amervideo/ehold/sql/local/HoldAvpSQL.xml.

--- The error occurred while applying a parameter map.  
--- Check the updateAvp-InlineParameterMap.  
--- Check the parameter mapping for the 'id' property.  
--- Cause: java.sql.SQLException: Invalid column type
	at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdat
e(GeneralStatement.java:86)
	at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.update(SqlMapExecut
orDelegate.java:500)
	at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.update(SqlMapSessionImpl
.java:89)
	at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.update(SqlMapClientImpl.j
ava:61)
	at
com.amervideo.ehold.dao.LocalAvpDAO.update(LocalAvpDAO.java:80)
	at
com.amervideo.ehold.service.WareService.addWare(WareService.java:126)
	at
eHoldTest.service.TestWareService.testAddWareWithOutCreateHold(TestWareS
ervice.java:86)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:421)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
ner.java:305)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
nner.java:186)
Caused by: java.sql.SQLException: Invalid column type
	at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
	at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
	at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:273)
	at
oracle.jdbc.driver.OracleStatement.get_internal_type(OracleStatement.jav
a:4560)
	at
oracle.jdbc.driver.OraclePreparedStatement.setNull(OraclePreparedStateme
nt.java:869)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at
com.ibatis.common.jdbc.logging.PreparedStatementLogProxy.invoke(Prepared
StatementLogProxy.java:65)
	at $Proxy1.setNull(Unknown Source)
	at
com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParamete
r(BasicParameterMap.java:171)
	at
com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParamete
rs(BasicParameterMap.java:125)
	at
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor
.java:80)
	at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteUp
date(GeneralStatement.java:195)
	at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdat
e(GeneralStatement.java:73)
	... 19 more

Caused by: 
java.sql.SQLException: Invalid column type
	at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
	at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
	at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:273)
	at
oracle.jdbc.driver.OracleStatement.get_internal_type(OracleStatement.jav
a:4560)
	at
oracle.jdbc.driver.OraclePreparedStatement.setNull(OraclePreparedStateme
nt.java:869)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at
com.ibatis.common.jdbc.logging.PreparedStatementLogProxy.invoke(Prepared
StatementLogProxy.java:65)
	at $Proxy1.setNull(Unknown Source)
	at
com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParamete
r(BasicParameterMap.java:171)
	at
com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParamete
rs(BasicParameterMap.java:125)
	at
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor
.java:80)
	at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteUp
date(GeneralStatement.java:195)
	at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdat
e(GeneralStatement.java:73)
	at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.update(SqlMapExecut
orDelegate.java:500)
	at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.update(SqlMapSessionImpl
.java:89)
	at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.update(SqlMapClientImpl.j
ava:61)
	at
com.amervideo.ehold.dao.LocalAvpDAO.update(LocalAvpDAO.java:80)
	at
com.amervideo.ehold.service.WareService.addWare(WareService.java:126)
	at
eHoldTest.service.TestWareService.testAddWareWithOutCreateHold(TestWareS
ervice.java:86)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:421)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
ner.java:305)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
nner.java:186)

Caused by: 
java.sql.SQLException: Invalid column type
	at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
	at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
	at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:273)
	at
oracle.jdbc.driver.OracleStatement.get_internal_type(OracleStatement.jav
a:4560)
	at
oracle.jdbc.driver.OraclePreparedStatement.setNull(OraclePreparedStateme
nt.java:869)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at
com.ibatis.common.jdbc.logging.PreparedStatementLogProxy.invoke(Prepared
StatementLogProxy.java:65)
	at $Proxy1.setNull(Unknown Source)
	at
com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParamete
r(BasicParameterMap.java:171)
	at
com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParamete
rs(BasicParameterMap.java:125)
	at
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor
.java:80)
	at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteUp
date(GeneralStatement.java:195)
	at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdat
e(GeneralStatement.java:73)
	at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.update(SqlMapExecut
orDelegate.java:500)
	at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.update(SqlMapSessionImpl
.java:89)
	at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.update(SqlMapClientImpl.j
ava:61)
	at
com.amervideo.ehold.dao.LocalAvpDAO.update(LocalAvpDAO.java:80)
	at
com.amervideo.ehold.service.WareService.addWare(WareService.java:126)
	at
eHoldTest.service.TestWareService.testAddWareWithOutCreateHold(TestWareS
ervice.java:86)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:421)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
ner.java:305)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
nner.java:186)



-----Original Message-----
From: Brandon Goodin [mailto:brandon.goodin@gmail.com] 
Sent: Friday, February 18, 2005 11:29 AM
To: ibatis-user-java@incubator.apache.org
Subject: Re: SqlMap transactions


Please post an example of your code.

Brandon


On Fri, 18 Feb 2005 11:23:35 -0500, Akins, Greg <gakins@amervideo.com>
wrote:
>  
> It appears that when the first statement executed in a sqlmap 
> transaction fails, then the subsequent endTransaction (called in a 
> catch) fails because there isn't a "started" transaction?
>   
> Is that correct?  If so, is it recommended that I just ignore the 
> SQLException error thrown from the endTransaction()?
>   
>  
> Greg Akins
> Software Engineer 
> Sony Electronics, STP Systems 
> 724.696.7322 (Sony) 
> 724.696.6147 (AV) 
> 724.454.7790 (Cell) 
> 412.590.3973 (Pager) 
>


Mime
View raw message