[jboss-user] [JBoss jBPM] - JBPM4: FOREIGN KEY problem

hexiaofeng do-not-reply at jboss.com
Wed Jul 8 00:40:32 EDT 2009


hi.  
   A question block me, Please help me .thank you very much.
   I download jbpm-4.0.CR1. Import jbpm.mysql.create.sql contents to MySql 5.

I create Order and TestUpdate , When I run TestUpdate , some exception print in cnosole. It seems question is FOREIGN KEY problem.
Please tell me how to fix it. Thank you very much.

Below are source code, and exceptin message.



package taskassign;

import java.io.Serializable;

public class Order implements Serializable {

	  /**
	 * 
	 */
	private static final long serialVersionUID = 7122991894288933400L;
	String owner;
    String form;
    
	  public Order(String owner,String form) {
	    this.owner = owner;
	    this.form = form;
	  }

	  public String getOwner() {
	    return owner;
	  }

	  public void setOwner(String owner) {
	    this.owner = owner;
	  }
	  
	  public String getForm() {
		    return form;
		  }

		  public void setForm(String form) {
		    this.form = form;
		  }
	}



package taskassign;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.jbpm.api.Configuration;
import org.jbpm.api.Execution;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.HistoryService;
import org.jbpm.api.IdentityService;
import org.jbpm.api.ManagementService;
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessDefinitionQuery;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.ProcessInstanceQuery;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.TaskService;
import org.jbpm.api.cmd.CommandService;
import org.jbpm.api.task.Task;

public class TestUpdate {

	protected ProcessEngine processEngine = null;

	protected RepositoryService repositoryService;
	protected ExecutionService executionService;
	protected ManagementService managementService;
	protected TaskService taskService;
	protected HistoryService historyService;
	protected IdentityService identityService;
	protected CommandService commandService;
	long deploymentDbid;
	protected List registeredDeployments = new ArrayList();
	protected ProcessInstance processInstance;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TestUpdate test = new TestUpdate();
		test.init();
		test.doCreate();
		
		//test.doCheckTask("hexiaof");
		//test.doCheckTask("hexiaofeng");
		
		test.doTaskAssign();
		test.doCheckTask("hexiaof");
		//test.doCheckTask("hexiaofeng");
		 
		test.searchPID();
		test.doTaskReview();
		//test.doCheckTask("hexiaof");
		test.doCheckTask("hexiaofeng");	
		test.doCompleteTask();
		 
		test.del();
		 
	}

	private void init() {

		processEngine = new Configuration().buildProcessEngine();

		repositoryService = processEngine.get(RepositoryService.class);
		executionService = processEngine.getExecutionService();
		historyService = processEngine.getHistoryService();
		managementService = processEngine.getManagementService();
		taskService = processEngine.getTaskService();
		identityService = processEngine.getIdentityService();
		commandService = processEngine.get(CommandService.class);

		deploymentDbid = repositoryService.createDeployment()
				.addResourceFromClasspath("taskassign/process.jpdl.xml").deploy();

		processInstance = executionService
				.startProcessInstanceByKey("TaskDemo");
		processInstance = executionService
		        .startProcessInstanceByKey("TaskDemo","asd");
		System.out.println("processInstance.getId===========:"+processInstance.getId());
		System.out.println("deploymentDbid===========:"+deploymentDbid);
	}
	
 

	private void doCreate() {
		System.out.println("<<<=====doCreate=====");
		Map<String, Object> variables = new HashMap<String, Object>();
		variables.put("order", new Order("hexiaof","formID"));
		variables.put("form", "formID");
		String executionId = processInstance.findActiveExecutionIn("create").getId();
		processInstance = executionService.signalExecutionById(executionId,
				"toTaskAssign",variables);
		System.out.println("TaskAssign is " + processInstance.isActive("TaskAssign"));
	}
	
	private void doCheckTask(String username){
		System.out.println("<<<=====doCheckTask=====:"+username);
		List taskList = taskService.findPersonalTasks(username);
		System.out.println(username+"=====tasks number=====:"+taskList.size());
		
		Task task = null;
		long taskDBId = -1;
		for(int i=0;i<taskList.size();i++){
			task = taskList.get(i);
			System.out.println("=====tasks getName=====:"+task.getName());
			System.out.println("=====tasks getForm=====:"+task.getForm());
			System.out.println("=====tasks getDescription=====:"+task.getDescription());
			System.out.println("=====tasks getPriority=====:"+task.getPriority());
			System.out.println("=====tasks getPriority=====:"+task.getAssignee());
			taskDBId = task.getDbid();
			System.out.println("=====tasks getDbid=====:"+taskDBId);
			
			Set variableNames = taskService.getVariableNames(taskDBId);
			Map<String, Object> variables = taskService.getVariables(taskDBId, variableNames);
			System.out.println("form value is "+variables.get("form"));
			taskService.completeTask(taskDBId);
			
			System.out.println(username+" complete the task:"+task.getName());
		}
		taskList = taskService.findPersonalTasks(username);
		System.out.println(username+"=====tasks number=====:"+taskList.size());
		
	}
	
	private void doTaskAssign() {
		System.out.println("<<<=====doTaskAssign=====");
		Map<String, Object> variables = new HashMap<String, Object>();
		variables.put("order", new Order("hexiaofeng","123"));
		variables.put("formID", "formID123123");
	    String executionId = processInstance.findActiveExecutionIn("TaskAssign").getId();
		processInstance = executionService.signalExecutionById(executionId,
				"toTaskReview",variables);
		System.out.println("TaskReview is " + processInstance.isActive("TaskReview"));
	}

	private void doTaskReview() {
		System.out.println("<<<=====doTaskReview=====");
		ProcessInstance pi = processEngine.getExecutionService().findProcessInstanceById(this.processInstance.getId());
	    String executionId = pi.findActiveExecutionIn("TaskReview").getId();
		processInstance = executionService.signalExecutionById(executionId,
				"tocompleteTask");
		System.out.println("End is " + processInstance.isActive("completeTask"));
	}
	
	private void doCompleteTask() {
		System.out.println("<<<=====docompleteTask=====");
	    String executionId = processInstance.findActiveExecutionIn("completeTask").getId();
		processInstance = executionService.signalExecutionById(executionId,
				"toEnd");
		System.out.println("End is " + processInstance.isActive("End"));
	}
	
	private void del(){
		System.out.println("<<<=====del=====");
		ProcessInstance pi = processEngine.getExecutionService().findProcessInstanceById(this.processInstance.getId());
		String executionId = pi.findActiveExecutionIn("End").getId();
		processInstance = executionService.signalExecutionById(executionId);
//		
		executionService.endProcessInstance(this.processInstance.getId(),"end");
		//repositoryService.deleteDeployment(this.deploymentDbid);
	}
}

I add "----" in xml. if you want to try it, please remove "----".

<===?xml version="1.0" encoding="UTF-8"?>

<----process name="TaskDemo" xmlns="http://jbpm.org/4.0/jpdl">
 
	<----start>
		<----transition to="create">
	<----/start>


	<----state name="create">
		<----transition name="toTaskAssign" to="TaskAssign">
	<----/state>

	<----task name="TaskAssign" assignee="#{order.owner}">
		<----transition name="toTaskReview" to="TaskReview">
	<----/task>

	<----task name="TaskReview" assignee="#{order.owner}">
		<----transition name="tocompleteTask" to="completeTask">
	<----/task>

	<----state name="completeTask">
		<----transition name="toEnd" to="End">
	<----/state>

	<----end name="End">
 
<----/process>


2009-7-8 10:23:56 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1451, SQLState: 23000
2009-7-8 10:23:56 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Cannot delete or update a parent row: a foreign key constraint fails (`jbpm4/jbpm4_execution`, CONSTRAINT `FK_EXEC_INSTANCE` FOREIGN KEY (`INSTANCE_`) REFERENCES `jbpm4_execution` (`DBID_`))
2009-7-8 10:23:56 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
Throwable occurred: org.hibernate.exception.ConstraintViolationException: could not delete: [org.jbpm.jpdl.internal.model.JpdlExecution#2]
	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.jbpm.pvm.internal.tx.HibernateSessionResource.prepare(HibernateSessionResource.java:54)
	at org.jbpm.pvm.internal.tx.StandardTransaction.commit(StandardTransaction.java:106)
	at org.jbpm.pvm.internal.tx.StandardTransaction.complete(StandardTransaction.java:65)
	at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:61)
	at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:54)
	at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
	at org.jbpm.pvm.internal.svc.ExecutionServiceImpl.signalExecutionById(ExecutionServiceImpl.java:87)
	at taskassign.TestUpdate.doCompleteTask(TestUpdate.java:169)
	at taskassign.TestUpdate.main(TestUpdate.java:59)
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`jbpm4/jbpm4_execution`, CONSTRAINT `FK_EXEC_INSTANCE` FOREIGN KEY (`INSTANCE_`) REFERENCES `jbpm4_execution` (`DBID_`))
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
	at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2551)
	... 17 more
Exception in thread "main" org.hibernate.exception.ConstraintViolationException: could not delete: [org.jbpm.jpdl.internal.model.JpdlExecution#2]
	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.jbpm.pvm.internal.tx.HibernateSessionResource.prepare(HibernateSessionResource.java:54)
	at org.jbpm.pvm.internal.tx.StandardTransaction.commit(StandardTransaction.java:106)
	at org.jbpm.pvm.internal.tx.StandardTransaction.complete(StandardTransaction.java:65)
	at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:61)
	at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:54)
	at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
	at org.jbpm.pvm.internal.svc.ExecutionServiceImpl.signalExecutionById(ExecutionServiceImpl.java:87)
	at taskassign.TestUpdate.doCompleteTask(TestUpdate.java:169)
	at taskassign.TestUpdate.main(TestUpdate.java:59)
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`jbpm4/jbpm4_execution`, CONSTRAINT `FK_EXEC_INSTANCE` FOREIGN KEY (`INSTANCE_`) REFERENCES `jbpm4_execution` (`DBID_`))
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
	at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2551)
	... 17 more


View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4242317#4242317

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4242317



More information about the jboss-user mailing list