将activiti的databaseSchemaUpdate设置为drop-create抛出DbSqlSession 错误

今天在测试activiti的databaseSchemaUpdate属性的drop-create的时候一直抛出org.activiti.engine.impl.db.DbSqlSession错误信息,开始有点疑惑,折腾了很久才知道,原来是我将activiti数据库中的某些表或者记录删除,造成外键约束混乱,才会抛出这个错误。

今天在测试activiti的databaseSchemaUpdate属性的drop-create的时候一直抛出org.activiti.engine.impl.db.DbSqlSession错误信息,开始有点疑惑,折腾了很久才知道,原来是我将activiti数据库中的某些表或者记录删除,造成外键约束混乱,才会抛出这个错误。

错误信息:

7 [main] INFO org.activiti.engine.ProcessEngines - Initializing process engine using configuration 'file:/F:/Project_All/Eclipase_Workspace/Activiti_test01/bin/activiti.cfg.xml'

7 [main] INFO org.activiti.engine.ProcessEngines - initializing process engine for resource file:/F:/Project_All/Eclipase_Workspace/Activiti_test01/bin/activiti.cfg.xml

2015-2-14 9:20:40 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions

信息: Loading XML bean definitions from resource loaded through InputStream

5562 [main] INFO org.activiti.engine.impl.db.DbSqlSession - performing drop on engine with resource org/activiti/db/drop/activiti.mysql.drop.engine.sql

12467 [main] ERROR org.activiti.engine.impl.db.DbSqlSession - problem during schema drop, statement drop index ACT_IDX_VARIABLE_TASK_ID on ACT_RU_VARIABLE

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'activiti.act_ru_variable' doesn't exist

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:407)

at com.mysql.jdbc.Util.getInstance(Util.java:382)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3603)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3535)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1989)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2150)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2620)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2570)

at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:779)

at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:622)

at org.activiti.engine.impl.db.DbSqlSession.executeSchemaResource(DbSqlSession.java:930)

at org.activiti.engine.impl.db.DbSqlSession.executeSchemaResource(DbSqlSession.java:881)

at org.activiti.engine.impl.db.DbSqlSession.executeMandatorySchemaResource(DbSqlSession.java:698)

at org.activiti.engine.impl.db.DbSqlSession.dbSchemaDrop(DbSqlSession.java:679)

at org.activiti.engine.impl.db.DbSqlSession.performSchemaOperationsProcessEngineBuild(DbSqlSession.java:1000)

at org.activiti.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:25)

at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24)

at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57)

at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)

at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)

at org.activiti.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:72)

at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:363)

at org.activiti.engine.ProcessEngines.buildProcessEngine(ProcessEngines.java:194)

at org.activiti.engine.ProcessEngines.initProcessEnginFromResource(ProcessEngines.java:167)

at org.activiti.engine.ProcessEngines.init(ProcessEngines.java:98)

at org.activiti.engine.ProcessEngines.getProcessEngine(ProcessEngines.java:224)

at org.activiti.engine.ProcessEngines.getDefaultProcessEngine(ProcessEngines.java:217)

at com.bug315.ActivitiTest01.main(ActivitiTest01.java:15)

17427 [main] ERROR org.activiti.engine.impl.db.DbSqlSession - problem during schema drop, statement alter table ACT_RU_VARIABLE 

drop FOREIGN KEY ACT_FK_VAR_EXE

解决办法:

手动将activiti的所有表删除,然后修改activiti.cfg.xml配置文件中的databaseSchemaUpdate=“drop-create”,最后启动activiti引擎,此时会出现表不存在等错误,因为表已经被你手动删除了。执行完后,再启动activiti引擎,这个问题就不再抛出了。

databaseSchemaUpdate属性的取值:

  • flase: 默认值。activiti在启动时,会对比数据库表中保存的版本,如果没有表或者版本不匹配,将抛出异常。

  • true: activiti会对数据库中所有表进行更新操作。如果表不存在,则自动创建。

  • create_drop: 在activiti启动时创建表,在关闭时删除表(必须手动关闭引擎,才能删除表)。

  • drop-create: 在activiti启动时删除原来的旧表,然后在创建新表(不需要手动关闭引擎)。

学习有两忌,自高和自狭。 —— 书摘
0 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站专注于 Java、数据库(MySQL、Oracle)、Linux、软件架构及大数据等多领域技术知识分享。涵盖丰富的原创与精选技术文章,助力技术传播与交流。无论是技术新手渴望入门,还是资深开发者寻求进阶,这里都能为您提供深度见解与实用经验,让复杂编码变得轻松易懂,携手共赴技术提升新高度。如有侵权,请来信告知:hxstrive@outlook.com
公众号