org.hibernate.exception.ConstraintViolationException: could not delete: [org.jbp

用jbpm4做流程时候将sqlserver数据库改为mysql数据库出现的问题,就是在流程结束时候不能正常结束,错误如下:

警告: SQL Error: 1451, SQLState: 23000
二月 28, 2013 11:05:58 上午 org.hibernate.util.JDBCExceptionReporter logExceptions
严重: Cannot delete or update a parent row: a foreign key constraint fails (`myworkflow`.`jbpm4_execution`, CONSTRAINT `FK_EXEC_INSTANCE` FOREIGN KEY (`INSTANCE_`) REFERENCES `jbpm4_execution` (`DBID_`))
二月 28, 2013 11:05:58 上午 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
严重: Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not delete: [org.jbpm.pvm.internal.model.ExecutionImpl#10004]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2569)
at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2725)
at org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:97)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:172)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:412)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy9.addHandleTask(Unknown Source)

分析原因:是jbpm表我有外键关联,不能删除,可是用sqlserver数据库就可以正常结束流程,为什么换成mysql数据库就不行了呢?经过思考发现,可能是配置mysql数据库的配置文件有问题,最后发现是配置的mysql的方言的问题。

解决方法:
我的mysql方言配置如下:

<prop key="hibernate.dialect">com.sense.workflow.util.ExtMySQL5Dialect </prop>

这里我专门写了一个类,为了解决字段hibernate和java映射的错误。而原先这个类的代码如下:

package com.sense.workflow.util;
import java.sql.Types;
import org.hibernate.Hibernate;
import org.hibernate.dialect.MySQL5Dialect;
/**
* mysql注册类型映射
* @author Kevin12
*
*/
public class ExtMySQL5Dialect extends MySQL5Dialect{
public ExtMySQL5Dialect(){
super();
this.registerHibernateType(Types.LONGVARCHAR, Hibernate.STRING.getName());
}
}

要将该类中继承的MySQL5Dialect改为MySQLInnoDBDialect即可,改后的代码如下:

package com.sense.workflow.util;
import java.sql.Types;
import org.hibernate.Hibernate;
import org.hibernate.dialect.MySQLInnoDBDialect;
/**
* mysql注册类型映射
* @author Kevin12
*
*/
public class ExtMySQL5Dialect extends MySQLInnoDBDialect{
public ExtMySQL5Dialect(){
super();
this.registerHibernateType(Types.LONGVARCHAR, Hibernate.STRING.getName());
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值