NutzCN Logo
问答 nutz chain多个动作,更新事件,计算时差,如何使用
发布于 1729天前 作者 qq_edffd6b4 1809 次浏览 复制 上一个帖子 下一个帖子
标签:

想批量更新一批数据,timeset,默认值已有,timeend现在批量更新,同时计算duration并更新。
使用下述代码会报错 Column 'duration' cannot be null
也就是duration计算出来的值为null
请指教该如何使用?

dao.update(EventRecord.class, Chain.makeSpecial("timeend", "now()").addSpecial("triggerend", data.getId()).addSpecial("duration", "TIMESTAMPDIFF(SECOND,  timeset,timeend)"), Cnd.where("timeend", "is", null));
3 回复

triggerend不是addSpecial吧?

add("triggerend", data.getId())

对应的日志贴一下

我大概看到问题点了。
本意是查询timeend为null的,然后依次执行timeend,triggerend,duration更新值的操作。
发现当timeend更新了后,仍然是用 where timeend is null来查询并进行更新

[DEBUG] 10:00:58.675 org.nutz.dao.util.Daos.updateBySpecialChain(Daos.java:427) - UPDATE eventrecord SET duration=timeend-timeset   WHERE timeend IS NULL 
Exception in thread "Thread-3" org.nutz.dao.DaoException: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'duration' cannot be null
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:92)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:81)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240)
	at org.nutz.dao.util.Daos.updateBySpecialChain(Daos.java:429)
	at org.nutz.dao.impl.NutDao.update(NutDao.java:309)
	at com.lingxi.mqtt.task.DataGenerator.run(DataGenerator.java:128)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'duration' cannot be null
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
	at com.mysql.jdbc.Util.getInstance(Util.java:408)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3970)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
	at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)
	at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)
	at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5098)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeUpdate(FilterChainImpl.java:2723)
	at com.alibaba.druid.filter.FilterAdapter.preparedStatement_executeUpdate(FilterAdapter.java:1069)
	at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_executeUpdate(FilterEventAdapter.java:491)
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_executeUpdate(FilterChainImpl.java:2721)
	at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.executeUpdate(PreparedStatementProxyImpl.java:158)
	at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeUpdate(DruidPooledPreparedStatement.java:253)
	at org.nutz.dao.util.Daos$2.invoke(Daos.java:435)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:125)
	... 6 more
添加回复
请先登陆
回到顶部