jBPM4.4中配备MySQL的hibernate方言MySQLInnoDBDialect

来源:互联网 发布:淘宝售后管理软件 编辑:程序博客网 时间:2024/05/02 00:39

很坑的一个问题。如果使用错误的mysql方言,则在级联删除的时候,会报mysql级联删除错误。


jBPM4.4中配置MySQL的hibernate方言MySQLInnoDBDialect 

最初的jbpm.hibernate.cfg.xml中,对MySQL的方言配置成了 org.hibernate.dialect.MySQLDialect,发布流程的时候遇到下述错误: 

Cannot delete or update a parent row: a foreign key constraint fails 

Could not synchronize database state with session 

将MySQL方言修改为 org.hibernate.dialect.MySQLInnoDBDialect问题解决 

看着上面好像问题是解决了:不过我却发现了一个问题,就是自动建表的问题,先看下面的代码: 

<?xml version="1.0" encoding="utf-8"?><!DOCTYPE hibernate-configuration PUBLIC          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>  <session-factory>          <!-- 不知道为什么,把hibernate.dialect改成org.hibernate.dialect.MySQLInnoDBDialect,,如果你把表删除了的话,不能自动建表        但是运行的时候又得换成org.hibernate.dialect.MySQLInnoDBDialect才不会报错,,,纠结了。。     -->   <!--  <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> -->    <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>     <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jbpm</property>     <property name="hibernate.connection.username">root</property>     <property name="hibernate.connection.password">root</property>     <property name="hibernate.hbm2ddl.auto">update</property>     <property name="hibernate.format_sql">true</property>          <mapping resource="jbpm.repository.hbm.xml" />     <mapping resource="jbpm.execution.hbm.xml" />     <mapping resource="jbpm.history.hbm.xml" />     <mapping resource="jbpm.task.hbm.xml" />     <mapping resource="jbpm.identity.hbm.xml" />       </session-factory></hibernate-configuration>


这句配置 <property name="hibernate.hbm2ddl.auto">update</property>是习以为常的自动建表语句,它的属性值有:create , update ,create-drop等等,代表不同的建表模式。 
我是调用java代码来建表的,如下: 

public static void main(String arg[]) {//必须使用的,流程引擎ProcessEngine processEngine = Configuration.getProcessEngine();RepositoryService repositoryService = processEngine.getRepositoryService();}


结果发现这样的方式只能用 org.hibernate.dialect.MySQLInnoDBDialect这个方言才能使用,换成了 org.hibernate.dialect.MySQLInnoDBDialect的话只能删除,不能重新建表了。。。。真是个奇怪的问题?有没有知道原因的?
0 0
原创粉丝点击