环境信息
canal version 1.1.4 mysql version 8.0
问题描述
在使用canal admin时,在canal启动时无法注册到admin中,报[Column 'modified_time' cannot be null]
2020-12-29 10:48:56.603 [http-nio-8089-exec-7] ERROR c.a.otter.canal.admin.handler.CustomExceptionHandler - Error[Column 'modified_time' cannot be null] javax.persistence.PersistenceException: Error[Column 'modified_time' cannot be null] at io.ebean.config.dbplatform.SqlCodeTranslator.translate(SqlCodeTranslator.java:52) at io.ebean.config.dbplatform.DatabasePlatform.translate(DatabasePlatform.java:223) at io.ebeaninternal.server.persist.dml.DmlBeanPersister.execute(DmlBeanPersister.java:83) at io.ebeaninternal.server.persist.dml.DmlBeanPersister.insert(DmlBeanPersister.java:49) at io.ebeaninternal.server.core.PersistRequestBean.executeInsert(PersistRequestBean.java:1295) at io.ebeaninternal.server.core.PersistRequestBean.executeNow(PersistRequestBean.java:797) at io.ebeaninternal.server.core.PersistRequestBean.executeNoBatch(PersistRequestBean.java:852) at io.ebeaninternal.server.core.PersistRequestBean.executeOrQueue(PersistRequestBean.java:843) at io.ebeaninternal.server.persist.DefaultPersister.insert(DefaultPersister.java:523) at io.ebeaninternal.server.persist.DefaultPersister.insert(DefaultPersister.java:469) at io.ebeaninternal.server.persist.DefaultPersister.save(DefaultPersister.java:452) at io.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1701) at io.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1693) at io.ebean.Model.save(Model.java:192) at com.alibaba.otter.canal.admin.model.Model.save(Model.java:28) at com.alibaba.otter.canal.admin.service.impl.NodeServerServiceImpl.save(NodeServerServiceImpl.java:47) at com.alibaba.otter.canal.admin.service.impl.PollingConfigServiceImpl.autoRegister(PollingConfigServiceImpl.java:48) at com.alibaba.otter.canal.admin.controller.PollingConfigController.canalConfigPoll(PollingConfigController.java:56) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
实际执行情况
If there is an exception, please attach the exception trace: 2020-12-29 10:48:56.603 [http-nio-8089-exec-7] ERROR c.a.otter.canal.admin.handler.CustomExceptionHandler - Error[Column 'modified_time' cannot be null] javax.persistence.PersistenceException: Error[Column 'modified_time' cannot be null] at io.ebean.config.dbplatform.SqlCodeTranslator.translate(SqlCodeTranslator.java:52) at io.ebean.config.dbplatform.DatabasePlatform.translate(DatabasePlatform.java:223) at io.ebeaninternal.server.persist.dml.DmlBeanPersister.execute(DmlBeanPersister.java:83) at io.ebeaninternal.server.persist.dml.DmlBeanPersister.insert(DmlBeanPersister.java:49) at io.ebeaninternal.server.core.PersistRequestBean.executeInsert(PersistRequestBean.java:1295) at io.ebeaninternal.server.core.PersistRequestBean.executeNow(PersistRequestBean.java:797) at io.ebeaninternal.server.core.PersistRequestBean.executeNoBatch(PersistRequestBean.java:852) at io.ebeaninternal.server.core.PersistRequestBean.executeOrQueue(PersistRequestBean.java:843) at io.ebeaninternal.server.persist.DefaultPersister.insert(DefaultPersister.java:523) at io.ebeaninternal.server.persist.DefaultPersister.insert(DefaultPersister.java:469) at io.ebeaninternal.server.persist.DefaultPersister.save(DefaultPersister.java:452) at io.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1701) at io.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1693) at io.ebean.Model.save(Model.java:192) at com.alibaba.otter.canal.admin.model.Model.save(Model.java:28) at com.alibaba.otter.canal.admin.service.impl.NodeServerServiceImpl.save(NodeServerServiceImpl.java:47) at com.alibaba.otter.canal.admin.service.impl.PollingConfigServiceImpl.autoRegister(PollingConfigServiceImpl.java:48) at com.alibaba.otter.canal.admin.controller.PollingConfigController.canalConfigPoll(PollingConfigController.java:56) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
Just put your stack trace here! 通过打印InsertHandler发现,在使用jpa时发出的sql为:sql=@String[insert into canal_node_server (cluster_id, name, ip, admin_port, metric_port, tcp_port, status, modified_time) values (?,?,?,?,?,?,?,?)]; 然而提供的sql脚本中modified_time是有默认值的modified_time
timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 在构造NodeServer时没有setModifiedTime,但是jpa默认插入null导致入库失败了; server = new NodeServer(); server.setName(ip); server.setIp(ip); server.setAdminPort(adminPort); server.setTcpPort(adminPort + 1); server.setMetricPort(adminPort + 2); if (StringUtils.isNotEmpty(cluster)) { CanalCluster clusterConfig = CanalCluster.find.query().where().eq("name", cluster).findOne(); if (clusterConfig == null) { throw new ServiceException("auto cluster : " + cluster + " is not found."); }
server.setClusterId(clusterConfig.getId());
}
nodeServerService.save(server);
原提问者GitHub用户zwbVsA
可以在构造NodeServer 时手动将modified_time 设置为当前时间。
原回答者GitHub用户wingerx
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。