ffmmx's Blog

Happy coding

JBPM4 使用MYSQL作为后端,执行结束流程报错。

 

首先,分析配置文件hibernate.cfg.xml的内容,其中在默认设置是用 HSQL(开源的数据库),这是一个内存数据库,这种内存数据库用来代替项目实际所用的数据库来做单元测试挺不错的。不过在我们的真实开发中,还是使用oracle等。

MySQL 的更改如下:
   <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
   <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
   <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/onlineas</property>
   <property name="hibernate.connection.username">root</property>
   <property name="hibernate.connection.password">123456</property>

运行junit测试,抛异常
07:48:16,655 INF | [DefaultCommandService] exception while executing command org.jbpm.pvm.internal.cmd.DeleteDeploymentCmd@8a2023
org.hibernate.exception.ConstraintViolationException: could not delete: [org.jbpm.pvm.internal.model.ExecutionImpl#10]

....


Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`onlineas/jbpm4_execution`, CONSTRAINT `FK_EXEC_INSTANCE` FOREIGN KEY (`INSTANCE_`) REFERENCES `jbpm4_execution` (`DBID_`))

 

解决办法:修改dialect即可,<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>