开发者社区> 问答> 正文

jpa canal_node_server 入库失败

环境信息

canal version 1.1.4 mysql version 8.0

问题描述

在使用canal admin时,在canal启动时无法注册到admin中,报[Column 'modified_time' cannot be null]

提问140.png

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

展开
收起
山海行 2023-04-27 19:16:55 96 0
1 条回答
写回答
取消 提交回答
  • 可以在构造NodeServer 时手动将modified_time 设置为当前时间。

    原回答者GitHub用户wingerx

    2023-04-28 14:00:36
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载