NutzCN Logo
问答 nutz-1.b.51-SNAPSHOT.jar 事务问题,导致报错没有回滚
发布于 3334天前 作者 qq_710cab78 2136 次浏览 复制 上一个帖子 下一个帖子
标签: dao

我用的是nutz-1.b.51-SNAPSHOT.jar这个版本的,是不是事务有问题 QQ图片20150930120333.png
Trans.exec(new Atom(){
public void run() {
//这里有插入代码
//这里有报错的代码
}
});
发现中间报错后,上面的插入代码也没有回滚,直接提交到数据库了。

5 回复
  1. mysql的话, 一般是是表不支持事务, 用了MyISAM引擎
  2. 看你代码没有任何insert/update操作的痕迹

数据库配置:
var ioc = {

    config : {
       type : "org.nutz.ioc.impl.PropertiesProxy",
       fields : {
         paths : ["/conf/myapp.properties"]
       }
    },

    dataSource : {
       type :"com.mchange.v2.c3p0.ComboPooledDataSource",
       events : {
         depose :"close"
       },
       fields : {
         driverClass : {java :"$config.get('db-driver')"},
         jdbcUrl             : {java :"$config.get('db-url')"},
         user         : {java :"$config.get('db-username')"},
         password        : {java :"$config.get('db-password')"},
         minPoolSize     : 5,
         initialPoolSize : 10,
         maxPoolSize     : 100,
         testConnectionOnCheckin : true,
         automaticTestTable : "C3P0TestTable",
         idleConnectionTestPeriod : 18000,
         maxIdleTime : 300,
         maxStatements : 0,
         numHelperThreads : 5
       }
    },
    // Dao
    dao : {
       type :'com.ErpDao',
       args : [ {refer :"dataSource"}]
    }
};

myapp.properties 文件
db-driver=com.mysql.jdbc.Driver
db-url=jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=UTF-8
db-username=my
db-password=123456
db-maxpoolsize=100
db-validationquery=select 0 from dual
代码太长了,上面只例举了一部分,但确实是报异常的上面有插入操作,比如CompanyDocument实体里面确实没有note字段,这时document.setNote(comNote); dao().update(document); 报错,但上面的插入和更新都执行了。
QQ截图20150930141531111111.gif

异常信息:
2015-09-30 14:07:51,357 [http-8082-5] ERROR com.okideaad.erp.common.module.CompanyModule - org.nutz.dao.DaoException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'note' in 'field list'
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:50)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:204)
at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
at org.nutz.dao.impl.NutDao.update(NutDao.java:220)
at com.okideaad.erp.common.module.CompanyModule$2.run(CompanyModule.java:479)
at org.nutz.trans.Trans.exec(Trans.java:165)
at org.nutz.trans.Trans.exec(Trans.java:123)
at com.okideaad.erp.common.module.CompanyModule.updateCompany(CompanyModule.java:405)
at FASTCLASS$$0._invoke(Unknown Source)
at org.nutz.lang.reflect.AbstractFastClass.invoke(AbstractFastClass.java:107)
at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:40)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:99)
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.NutActionChain.doChain(NutActionChain.java:40)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:64)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:175)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
at com.okideaad.erp.security.MenuUrlFilter.doFilter(MenuUrlFilter.java:66)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at com.okideaad.erp.security.MustChangePwdFilter.doFilter(MustChangePwdFilter.java:31)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
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 com.okideaad.erp.security.EmailSSOFilter.doFilter(EmailSSOFilter.java:62)
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.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.okideaad.erp.filter.EncodingFilter.doFilter(EncodingFilter.java:34)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'note' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.Util.getInstance(Util.java:383)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1062)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4226)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4158)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2840)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1302)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:989)
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:261)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:76)
at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:249)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:31)
... 59 more

那看来是MyISAM引擎的问题了

show create table "不回滚的表名"

show create table T_cmn_suppliers_type_map;

'CREATE TABLE t_cmn_suppliers_type_map (
id bigint(20) NOT NULL AUTO_INCREMENT,
company_code varchar(50) NOT NULL COMMENT ''供应商编码'',
company_name varchar(50) DEFAULT NULL COMMENT ''供应商名称'',
type_code varchar(50) NOT NULL COMMENT ''供应商类别编码'',
type_name varchar(50) NOT NULL COMMENT ''供应商类别名称'',
PRIMARY KEY (id),
UNIQUE KEY UQ_T_cmn_suppliers_type_map_1 (company_code,type_code)
) ENGINE=MyISAM AUTO_INCREMENT=48 DEFAULT CHARSET=utf8 COMMENT=''供应商类别表'''

测试了几次发现该表的数据都更新了,我在刚在报异常的中间不过有其它表执行了回滚。
QQ截图20150930151231222222.gif

可以回滚的表
'CREATE TABLE t_cmn_company_contacts (
id bigint(20) NOT NULL AUTO_INCREMENT,
code varchar(50) NOT NULL COMMENT ''公司联系人表编码'',
company_code varchar(50) NOT NULL,
person_name varchar(50) NOT NULL,
tel varchar(50) DEFAULT NULL,
email varchar(100) DEFAULT NULL,
qq varchar(50) DEFAULT NULL,
fax varchar(50) DEFAULT NULL COMMENT ''传真号码'',
last_update_person varchar(50) DEFAULT NULL,
last_update_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY UQ_T_cmn_company_contacts_1 (company_code,person_name),
KEY company_code (company_code),
KEY code (code),
CONSTRAINT FK_T_cmn_company_contacts_1 FOREIGN KEY (company_code) REFERENCES t_cmn_company (code)
) ENGINE=InnoDB AUTO_INCREMENT=450 DEFAULT CHARSET=utf8 COMMENT=''联系人表'''

看来还真的是数据库MyISAM引擎的问题,用InnoDB引擎可以回滚。 谢谢wendal兽!!!

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