NutzCN Logo
问答 NutTxDao使用中的问题
发布于 2510天前 作者 shuxinyun 1870 次浏览 复制 上一个帖子 下一个帖子
标签:

使用的是Oracle数据库,是最简单的基本配置

NutTxDao tran=new NutTxDao(dao).setDebug(true);           
tran.beginRC();

这里多次执行,偶尔正常,总是存在出现如下错误的情况:
java.sql.SQLException: 调用中的无效参数
多次刷新,错误多次出现后,就出现下面错误
com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 15001, active 8, maxActive 8
必须重启应用才可以的

  For example:> "SELECT * FROM dbm_submit  WHERE parentId='9ad4b6c74d0e4fe0bad3c05858f19e11'"
[DEBUG] 2018-01-02 11:33:44,959 org.nutz.dao.impl.NutTxDao.begin(NutTxDao.java:114) - begin level=2 id=5musdgmiashleq58o656vg7vcn
[DEBUG] 2018-01-02 11:33:44,959 org.nutz.dao.impl.NutTxDao.rollback(NutTxDao.java:165) - rollback id=5musdgmiashleq58o656vg7vcn
[DEBUG] 2018-01-02 11:33:44,959 org.nutz.dao.impl.NutTxDao.rollback(NutTxDao.java:176) - Null Savepoint found, skip, id=5musdgmiashleq58o656vg7vcn
[DEBUG] 2018-01-02 11:33:44,959 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [GET ]URI=/dbm/open/transfer/9ad4b6c74d0e4fe0bad3c05858f19e1f 22ms

52 回复
/**
     * 获取数据对象对应Dao
     * @param database
     * @return
     */
    public Dao getDao(Dbm_database database){
        Dao _dao =null;
        if(Daos.containsKey(database.getId())){
            _dao= Daos.get(database.getId());
        }
        else {
            DruidDataSource dataSource = new DruidDataSource();
            dataSource.setUrl(database.getUrl());
            dataSource.setUsername(database.getUsername());
            dataSource.setPassword(database.getPassword());
            dataSource.setDefaultAutoCommit(database.isDefaultAutoCommit());
            dataSource.setMaxWait(database.getMaxWait());
            _dao = new NutDao(dataSource);
            Daos.put(database.getId(),_dao);
            Databses.put(database.getId(),dataSource);
        }
        return _dao;
    }

数据库连接没有释放的样子, 调用代码里面没加finally?

public void Close(String databaseId){
        if(Databses.containsKey(databaseId)){
            Databses.get(databaseId).close();
            Databses.remove(databaseId);
            Daos.remove(databaseId);
        }
    }

执行这个也是同样问题,感觉无用

try {
            for (NutMap nutMap : list) {
                this.submit(submit, nutMap,trans);
            }
            result.setData(list);
            for(String databaseId:trans.keySet()) {
                trans.get(databaseId).commit();
            }
        } catch (Throwable e) {
            for(String databaseId:trans.keySet()) {
                trans.get(databaseId).rollback();
            }
            throw Lang.makeThrow(e.getMessage());
        }
        finally {
            for(String databaseId:trans.keySet()) {
                dbmDatabaseService.Close(databaseId);
            }
        }

关闭数据库连接后:
java.sql.SQLException: 调用中的无效参数
这个错误出现,

这个错误
com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 15001, active 8, maxActive 8
就不出现了

虽然我这里使用的支持多个数据库的方式,但出现错误的时候只有一个数据库参与事务!

NutTxDao相关的代码

private void submit(Dbm_submit submit, NutMap nutMap,Map<String,NutTxDao> trans) {
        Dao dao = dbmDatabaseService.getDao(submit.getDatabaseId());
        if(!trans.containsKey(submit.getDatabaseId())){
            NutTxDao tran=new NutTxDao(dao).setDebug(true);
            trans.put(submit.getDatabaseId(),tran);
            tran.beginRC();
        }

然后就没有了??

后面的就是使用这个dao进行数据库的insert,update

Map<String,NutTxDao> trans =new HashMap<>();
        try {
            for (NutMap nutMap : list) {
                this.submit(submit, nutMap,trans);
            }
            result.setData(list);
            for(String databaseId:trans.keySet()) {
                trans.get(databaseId).commit();
            }
        } catch (Throwable e) {
            for(String databaseId:trans.keySet()) {
                trans.get(databaseId).rollback();
            }
            throw Lang.makeThrow(e.getMessage());
        }
        finally {
            for(String databaseId:trans.keySet()) {
                dbmDatabaseService.Close(databaseId);
            }
        }
 private void submit(Dbm_submit submit, NutMap nutMap,Map<String,NutTxDao> trans) {
        Dao dao = dbmDatabaseService.getDao(submit.getDatabaseId());
        if(!trans.containsKey(submit.getDatabaseId())){
            NutTxDao tran=new NutTxDao(dao).setDebug(true);
            trans.put(submit.getDatabaseId(),tran);
            tran.beginRC();
        }
        dao.insert("test",chain):
}

必死无疑... 自行看文档吧

看了好几次,找不出问题所在呀!提示一下!

看到了,close

try {
            for (NutMap nutMap : list) {
                this.submit(submit, nutMap,trans);
            }
            result.setData(list);
            for(String databaseId:trans.keySet()) {
                trans.get(databaseId).commit();
            }
        } catch (Throwable e) {
            for(String databaseId:trans.keySet()) {
                trans.get(databaseId).rollback();
            }
            result.setCode(1);
            result.setMsg(e.getMessage());
        }
        finally {
            for(String databaseId:trans.keySet()) {
                trans.get(databaseId).close();
            }
        }

java.sql.SQLException: 调用中的无效参数
这个错误还是出现,

问题在于你调用NutTxDao的那段代码, 不是trans之类的东西

NutTxDao的调用必须按下面的范式

try (NutTxDao tx = new ....) {
   xxxxx..x..x..x
    tx.commit();
}
catch () {
    tx.rollback();
}
finally {
    tx.close()
}

任何新建的NutTxDao对象, 最起码要调用close

我这里的trans仅仅是一个map的实例,保存NutTxDao实例的容器呀!

就拿这个说

 private void submit(Dbm_submit submit, NutMap nutMap,Map<String,NutTxDao> trans) {
        Dao dao = dbmDatabaseService.getDao(submit.getDatabaseId());
        if(!trans.containsKey(submit.getDatabaseId())){
            NutTxDao tran=new NutTxDao(dao).setDebug(true);
            trans.put(submit.getDatabaseId(),tran);
            tran.beginRC();
        }
        dao.insert("test",chain): // 这里要操作tran啊
}

擦, 你先把代码整理整理吧

好的,我完全按你的方式写写试试!

public Result submit(int authType,Dbm_submit submit, List<NutMap> list) {
        if (submit.getAuthType() > authType) {
            throw Lang.makeThrow("您暂不具有对应数据操作权限");
        }
        Result result = new Result();
        Map<String,NutTxDao> trans =new HashMap<>();
        dao = dbmDatabaseService.getDao(submit.getDatabaseId());
        NutTxDao tx=new NutTxDao(dao);
        try {
            tx.beginRC();
            for (NutMap nutMap : list) {
                this.submit(submit, nutMap,trans);
            }
            result.setData(list);           
            tx.commit();
        } catch (Throwable e) {            
            tx.rollback();
            result.setCode(1);
            result.setMsg(e.getMessage());
        }
        finally {
            tx.close();         
        }
        return result;
    }

错误依旧

dao是类里面的私有全局变量

dataSource.setRemoveAbandoned(true);
            dataSource.setRemoveAbandonedTimeout(1800);
            dataSource.setLogAbandoned(true);

问题依旧

是让你看泄露的代码... 配置这个是不能解决泄露的,但会打印泄露的日志

我写了个入口方法测试了一下, 循环1000次,创建然后close, 没有泄露

    @At
    public void tx() {
        for (int i = 0; i < 1000; i++) {
            NutTxDao tx = new NutTxDao(dao);
            try {
                tx.beginRC();
                tx.query(User.class, null);
                tx.commit();
            } catch (Throwable e) {
                tx.rollback();
            }
            finally {
                tx.close();
            }
        }
    }

我看了日志,没有泄露日志!奇怪了!我现在执行10次至少有2次出错!

是否与oracle有关呀!

试一下我的测试代码

话说, 你这maxActive才8个, 也太少了吧

嗯,我现在修改为100个试试

Dao dao = dbmDatabaseService.getDao(submit.getDatabaseId());
        for (int i = 0; i < 1000; i++) {
            NutTxDao tx = new NutTxDao(dao);
            try {
                tx.beginRC();
                tx.query("im_units", null);
                tx.commit();
            } catch (Throwable e) {
                tx.rollback();
                result.setCode(1);
                result.setMsg(e.getMessage());
                break;
            }
            finally {
                tx.close();
            }
        }
        return result;

只可以执行一次成功,循环第二次就报错!

贴报错信息看看

同样的代码,我用mysql就没有问题,用oracle就是出错

public Result submit(int authType, String submitId, List<NutMap> list) {
        Dao dao=dbmDatabaseService.getDao("9ad4b6c74d0e4fe0bad3c05858f19e1f");
        Result result = new Result();
        for (int i = 0; i < 1000; i++) {
            NutTxDao tx = new NutTxDao(dao);
            try {
                tx.beginRC();
                tx.query("im_units", null);
                tx.commit();
            } catch (Throwable e) {
                tx.rollback();
                result.setCode(1);
                result.setMsg(e.getMessage());
                break;
            }
            finally {
                tx.close();
            }
        }
        return result;
    }

java.sql.SQLException: 调用中的无效参数

贴报错信息

[INFO ] 2018-01-02 15:22:24,976 org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:103) - Get Connection from DataSource for JdbcExpert, if you lock at here, check your database server and configure
[INFO ] 2018-01-02 15:22:24,994 com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:785) - {dataSource-2} inited
[DEBUG] 2018-01-02 15:22:25,691 org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:188) - select expert : org.nutz.dao.impl.jdbc.oracle.OracleJdbcExpert
[DEBUG] 2018-01-02 15:22:25,692 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:199) - JDBC Driver --> 11.1.0.7.0-Production
[DEBUG] 2018-01-02 15:22:25,692 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:200) - JDBC Name   --> Oracle JDBC driver
[DEBUG] 2018-01-02 15:22:25,692 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:202) - JDBC URL    --> jdbc:oracle:thin:@//localhost:1521/orcl
[DEBUG] 2018-01-02 15:22:25,693 org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:221) - Database info --> ORACLE:[Oracle - Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options]
[DEBUG] 2018-01-02 15:22:25,704 org.nutz.dao.impl.NutTxDao.rollback(NutTxDao.java:176) - Null Savepoint found, skip, id=57snh80fqmgakp3dk40mitt5vl
[DEBUG] 2018-01-02 15:22:25,738 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [GET ]URI=/dbm/open/transfer/9ad4b6c74d0e4fe0bad3c05858f19e1f 1039ms
[DEBUG] 2018-01-02 15:22:27,907 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) - Found mapping for [GET] path=/dbm/open/transfer/9ad4b6c74d0e4fe0bad3c05858f19e1f : open.transfer(open.java:91)
[DEBUG] 2018-01-02 15:22:27,907 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:163) - Get 'shiroUtil'<class cn.wizzer.framework.util.ShiroUtil>
[DEBUG] 2018-01-02 15:22:27,908 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:163) - Get 'dateUtil'<class cn.wizzer.framework.util.DateUtil>
[DEBUG] 2018-01-02 15:22:27,908 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:163) - Get 'stringUtil'<class cn.wizzer.framework.util.StringUtil>
[DEBUG] 2018-01-02 15:22:27,909 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:163) - Get 'open'<class cn.wizzer.app.dbm.modules.controllers.open>
[DEBUG] 2018-01-02 15:22:27,911 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - SELECT * FROM im_units 
[DEBUG] 2018-01-02 15:22:27,944 org.nutz.dao.impl.NutTxDao.rollback(NutTxDao.java:176) - Null Savepoint found, skip, id=13a4c40skgh6ort07df6rol0u9
[DEBUG] 2018-01-02 15:22:27,946 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [GET ]URI=/dbm/open/transfer/9ad4b6c74d0e4fe0bad3c05858f19e1f 39ms
[DEBUG] 2018-01-02 15:22:31,963 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) - Found mapping for [GET] path=/dbm/open/transfer/9ad4b6c74d0e4fe0bad3c05858f19e1f : open.transfer(open.java:91)
[DEBUG] 2018-01-02 15:22:31,963 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:163) - Get 'shiroUtil'<class cn.wizzer.framework.util.ShiroUtil>
[DEBUG] 2018-01-02 15:22:31,963 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:163) - Get 'dateUtil'<class cn.wizzer.framework.util.DateUtil>
[DEBUG] 2018-01-02 15:22:31,964 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:163) - Get 'stringUtil'<class cn.wizzer.framework.util.StringUtil>
[DEBUG] 2018-01-02 15:22:31,964 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:163) - Get 'open'<class cn.wizzer.app.dbm.modules.controllers.open>
[DEBUG] 2018-01-02 15:22:35,270 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - SELECT * FROM im_units 
[DEBUG] 2018-01-02 15:22:45,337 org.nutz.dao.impl.NutTxDao.rollback(NutTxDao.java:176) - Null Savepoint found, skip, id=4e0lh6rc9mgs1qftqk4r3b3osu
[DEBUG] 2018-01-02 15:22:45,338 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [GET ]URI=/dbm/open/transfer/9ad4b6c74d0e4fe0bad3c05858f19e1f 13375ms

[DEBUG] 2018-01-02 15:29:59,574 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - SELECT * FROM im_units 
[ERROR] 2018-01-02 15:29:59,613 cn.wizzer.app.dbm.modules.services.impl.DbmInterfaceServiceImpl.transfer(DbmInterfaceServiceImpl.java:617) - java.sql.SQLException: 调用中的无效参数
org.nutz.dao.DaoException: java.sql.SQLException: 调用中的无效参数
	at org.nutz.dao.impl.NutTxDao.setSavepoint(NutTxDao.java:195)
	at org.nutz.dao.impl.NutTxDao.begin(NutTxDao.java:122)
	at org.nutz.dao.impl.NutTxDao.beginRC(NutTxDao.java:87)
	at cn.wizzer.app.dbm.modules.services.impl.DbmInterfaceServiceImpl.transfer(DbmInterfaceServiceImpl.java:613)
	at cn.wizzer.app.dbm.modules.controllers.open.transfer(open.java:93)
	at cn.wizzer.app.dbm.modules.controllers.open$FM$transfer$23edfb0bcd91a7f6baf12ce46e035e19.invoke(open.java)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:30)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.XssSqlFilterProcessor.process(XssSqlFilterProcessor.java:35)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.NutShiroProcessor.process(NutShiroProcessor.java:52)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.GlobalsSettingProcessor.process(GlobalsSettingProcessor.java:43)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:21)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
	at cn.wizzer.app.web.commons.filter.RouteFilter.doFilter(RouteFilter.java:28)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1613)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:541)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:190)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1592)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1239)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:481)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1561)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1141)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:118)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.Server.handle(Server.java:564)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:672)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:590)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: 调用中的无效参数
	at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
	at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:271)
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:445)
	at oracle.jdbc.driver.OracleSavepoint.<init>(OracleSavepoint.java:65)
	at oracle.jdbc.driver.PhysicalConnection.oracleSetSavepoint(PhysicalConnection.java:6114)
	at oracle.jdbc.driver.PhysicalConnection.setSavepoint(PhysicalConnection.java:5643)
	at com.alibaba.druid.pool.DruidPooledConnection.setSavepoint(DruidPooledConnection.java:770)
	at org.nutz.dao.impl.NutTxDao.setSavepoint(NutTxDao.java:185)
	... 70 more
[DEBUG] 2018-01-02 15:29:59,620 org.nutz.dao.impl.NutTxDao.rollback(NutTxDao.java:176) - Null Savepoint found, skip, id=43csjbm36sg4orfbrru1j02nsb
[DEBUG] 2018-01-02 15:29:59,646 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [GET ]URI=/dbm/open/transfer/9ad4b6c74d0e4fe0bad3c05858f19e1f 999ms

setSavepoint失败,奇怪了,驱动版本多少?? 数据库版本多少?

驱动版本:

<dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0</version>
        </dependency>

数据库是oracle11g

额, 难道是Savepoint的Name太长了?

这样写,看看是否报错

NutTxDao tx = new NutTxDao(dao) { // 创建一个匿名子类
    public NutTxDao begin(int transLevel) throws DaoException {
        if (this.conn != null)
            throw new DaoException("NutTxDao has been begined!!");
        id = R.UU32().substring(0, 6); // 减少SavePointName的长度
        if (debug)
            log.debugf("begin level=%d id=%s", transLevel, id);
        try {
            this.conn = dataSource.getConnection();
            this.conn.setTransactionIsolation(transLevel);
            if (this.conn.getAutoCommit() == true) {
                this.conn.setAutoCommit(false);
                _autoCommit = true;
            }
            setSavepoint(id);
        }
        catch (SQLException e) {
            throw new DaoException(e);
        }
        return this;
    }
};

Dao dao=dbmDatabaseService.getDao("9ad4b6c74d0e4fe0bad3c05858f19e1f");
        for (int i = 0; i < 1000; i++) {
            NutTxDao tx = new NutTxDao(dao) { // 创建一个匿名子类
                public NutTxDao begin(int transLevel) throws DaoException {
                    if (this.conn != null)
                        throw new DaoException("NutTxDao has been begined!!");
                    id = R.UU32().substring(0, 6); // 减少SavePointName的长度
                    if (debug)
                        log.debugf("begin level=%d id=%s", transLevel, id);
                    try {
                        this.conn = dataSource.getConnection();
                        this.conn.setTransactionIsolation(transLevel);
                        if (this.conn.getAutoCommit() == true) {
                            this.conn.setAutoCommit(false);
                            _autoCommit = true;
                        }
                        setSavepoint(id);
                    } catch (SQLException e) {
                        throw new DaoException(e);
                    }
                    return this;
                }
            };
            try {
                tx.beginRC();
                tx.query("im_units", null);
                tx.commit();
            } catch (Throwable e) {
                log.error(e);
                tx.rollback();
                result.setCode(1);
                result.setMsg(e.getMessage());
                break;
            } finally {
                tx.close();
            }
        }

错误依然

[DEBUG] 2018-01-02 16:30:17,978 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) - Found mapping for [GET] path=/dbm/open/transfer/9ad4b6c74d0e4fe0bad3c05858f19e1f : open.transfer(open.java:91)
[DEBUG] 2018-01-02 16:30:17,979 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:163) - Get 'shiroUtil'<class cn.wizzer.framework.util.ShiroUtil>
[DEBUG] 2018-01-02 16:30:17,979 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:163) - Get 'dateUtil'<class cn.wizzer.framework.util.DateUtil>
[DEBUG] 2018-01-02 16:30:17,980 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:163) - Get 'stringUtil'<class cn.wizzer.framework.util.StringUtil>
[DEBUG] 2018-01-02 16:30:17,981 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:163) - Get 'open'<class cn.wizzer.app.dbm.modules.controllers.open>
[ERROR] 2018-01-02 16:30:17,983 cn.wizzer.app.dbm.modules.services.impl.DbmInterfaceServiceImpl.test(DbmInterfaceServiceImpl.java:622) - java.sql.SQLException: 调用中的无效参数
org.nutz.dao.DaoException: java.sql.SQLException: 调用中的无效参数
	at org.nutz.dao.impl.NutTxDao.setSavepoint(NutTxDao.java:195)
	at cn.wizzer.app.dbm.modules.services.impl.DbmInterfaceServiceImpl$2.begin(DbmInterfaceServiceImpl.java:610)
	at org.nutz.dao.impl.NutTxDao.beginRC(NutTxDao.java:87)
	at cn.wizzer.app.dbm.modules.services.impl.DbmInterfaceServiceImpl.test(DbmInterfaceServiceImpl.java:618)
	at cn.wizzer.app.dbm.modules.services.impl.DbmInterfaceServiceImpl.transfer(DbmInterfaceServiceImpl.java:649)
	at cn.wizzer.app.dbm.modules.controllers.open.transfer(open.java:93)
	at cn.wizzer.app.dbm.modules.controllers.open$FM$transfer$23edfb0bcd91a7f6baf12ce46e035e19.invoke(open.java)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:30)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.XssSqlFilterProcessor.process(XssSqlFilterProcessor.java:35)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.NutShiroProcessor.process(NutShiroProcessor.java:52)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.GlobalsSettingProcessor.process(GlobalsSettingProcessor.java:43)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:21)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
	at cn.wizzer.app.web.commons.filter.RouteFilter.doFilter(RouteFilter.java:28)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1613)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:541)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:190)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1592)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1239)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:481)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1561)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1141)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:118)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.Server.handle(Server.java:564)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
	at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:122)
	at org.eclipse.jetty.util.thread.strategy.ExecutingExecutionStrategy.invoke(ExecutingExecutionStrategy.java:58)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:201)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:133)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:672)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:590)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: 调用中的无效参数
	at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
	at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:271)
	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:445)
	at oracle.jdbc.driver.OracleSavepoint.<init>(OracleSavepoint.java:65)
	at oracle.jdbc.driver.PhysicalConnection.oracleSetSavepoint(PhysicalConnection.java:6114)
	at oracle.jdbc.driver.PhysicalConnection.setSavepoint(PhysicalConnection.java:5643)
	at com.alibaba.druid.pool.DruidPooledConnection.setSavepoint(DruidPooledConnection.java:770)
	at org.nutz.dao.impl.NutTxDao.setSavepoint(NutTxDao.java:185)
	... 75 more
[DEBUG] 2018-01-02 16:30:17,989 org.nutz.dao.impl.NutTxDao.rollback(NutTxDao.java:176) - Null Savepoint found, skip, id=5f6ths
[DEBUG] 2018-01-02 16:30:17,991 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [GET ]URI=/dbm/open/transfer/9ad4b6c74d0e4fe0bad3c05858f19e1f 12ms

晚上我装个oracle试试看,诡异了,难道不能走命名save point的?我印象中是可以的啊

ok,期待你的好消息

    public NutTxDao setSavepoint(String spId) {
        try {
            Savepoint sp = conn.setSavepoint(); // 不加spId就正常,回滚也没问题
            if (id.equals(spId))
                this.sp = sp;
            else {
                if (sps == null)
                    sps = new NutMap();
                sps.put(spId, sp);
            }
        }
        catch (SQLException e) {
            throw new DaoException(e);
        }
        return this;
    }

我提交修改了

更新后完美解决!

添加回复
请先登陆
回到顶部