sukawa 发表于 2013-2-7 08:18:49

请大家帮我看看到底应该怎么修改

最近刚开始研究osworkflow,出现了问题,有点郁闷,请大家看看。

我的数据库表创建文件为:mysql.sql

drop table if exists OS_PROPERTYENTRY cascade;
create table OS_PROPERTYENTRY
(
GLOBAL_KEY varchar(250) NOT NULL,
ITEM_KEY varchar(250) NOT NULL,
ITEM_TYPE tinyint,
STRING_VALUE varchar(255),
DATE_VALUE datetime,
DATA_VALUE blob,
FLOAT_VALUE float,
NUMBER_VALUE numeric,
primary key (GLOBAL_KEY, ITEM_KEY)
)TYPE=InnoDB;

-- Beginning of Default OSUser tables
drop table if exists OS_USER cascade;
create table OS_USER
(
    USERNAME varchar(100) NOT NULL,
    PASSWORDHASH mediumtext,
    primary key (USERNAME),
    index(USERNAME)
)TYPE=InnoDB;


drop table if exists OS_GROUP cascade;
create table OS_GROUP
(
    GROUPNAME varchar(20) NOT NULL,
    primary key (GROUPNAME)
)TYPE=InnoDB;

drop table if exists OS_MEMBERSHIP cascade;
create table OS_MEMBERSHIP
(
    USERNAME varchar(20) NOT NULL,
    GROUPNAME varchar(20) NOT NULL,
    primary key (USERNAME, GROUPNAME),
    index (USERNAME),
    foreign key (USERNAME) references OS_USER(USERNAME),
    index (GROUPNAME),
    foreign key (GROUPNAME) references OS_GROUP(GROUPNAME)
)TYPE=InnoDB;

-- End of Default OSUser tables



drop table if exists OS_WFENTRY cascade;
create table OS_WFENTRY
(
    ID bigint NOT NULL,
    NAME varchar(60),
    STATE integer,
    primary key (ID)
)TYPE=InnoDB;


drop table if exists OS_CURRENTSTEP;
create table OS_CURRENTSTEP
(
    ID bigint NOT NULL,
    ENTRY_ID bigint,
    STEP_ID integer,
    ACTION_ID integer,
    OWNER varchar(35),
    START_DATE datetime,
    FINISH_DATE datetime,
    DUE_DATE datetime,
    STATUS varchar(40),
CALLER varchar(35),

    primary key (ID),
    index (ENTRY_ID),
    foreign key (ENTRY_ID) references OS_WFENTRY(ID),
    index (OWNER),
    foreign key (OWNER) references OS_USER(USERNAME),
    index (CALLER),
    foreign key (CALLER) references OS_USER(USERNAME)
)TYPE=InnoDB;

drop table if exists OS_HISTORYSTEP;
create table OS_HISTORYSTEP
(
    ID bigint NOT NULL,
    ENTRY_ID bigint,
    STEP_ID integer,
    ACTION_ID integer,
    OWNER varchar(35),
    START_DATE datetime,
    FINISH_DATE datetime,
    DUE_DATE datetime,
    STATUS varchar(40),
    CALLER varchar(35),

    primary key (ID),
    index (ENTRY_ID),
    foreign key (ENTRY_ID) references OS_WFENTRY(ID),
    index (OWNER),
    foreign key (OWNER) references OS_USER(USERNAME),
    index (CALLER),
    foreign key (CALLER) references OS_USER(USERNAME)
)TYPE=InnoDB;

drop table if exists OS_CURRENTSTEP_PREV;
create table OS_CURRENTSTEP_PREV
(
    ID bigint NOT NULL,
    PREVIOUS_ID bigint NOT NULL,
    primary key (ID, PREVIOUS_ID),
    index (ID),
    foreign key (ID) references OS_CURRENTSTEP(ID),
    index (PREVIOUS_ID),
    foreign key (PREVIOUS_ID) references OS_HISTORYSTEP(ID)
)TYPE=InnoDB;

drop table if exists OS_HISTORYSTEP_PREV;
create table OS_HISTORYSTEP_PREV
(
    ID bigint NOT NULL,
    PREVIOUS_ID bigint NOT NULL,
    primary key (ID, PREVIOUS_ID),
    index (ID),
    foreign key (ID) references OS_HISTORYSTEP(ID),
    index (PREVIOUS_ID),
    foreign key (PREVIOUS_ID) references OS_HISTORYSTEP(ID)
)TYPE=InnoDB;

drop table if exists OS_STEPIDS;
CREATE TABLE OS_STEPIDS
(
ID bigint NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id)
)TYPE=InnoDB;

drop table if exists OS_ENTRYIDS;
CREATE TABLE OS_ENTRYIDS
(
ID bigint NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id)
)TYPE=InnoDB;


数据初始化文件为: initdata.sql

INSERT INTO OS_USER (USERNAME,PASSWORDHASH) VALUES ('employee1','123');
INSERT INTO OS_USER (USERNAME,PASSWORDHASH) VALUES ('hr1','123');
INSERT INTO OS_USER (USERNAME,PASSWORDHASH) VALUES ('manager1','123');

INSERT INTO OS_GROUP (GROUPNAME) VALUES ('employee');
INSERT INTO OS_GROUP (GROUPNAME) VALUES ('hr');
INSERT INTO OS_GROUP (GROUPNAME) VALUES ('manager');

INSERT INTO OS_MEMBERSHIP (USERNAME,GROUPNAME) VALUES ('employee1','employee');
INSERT INTO OS_MEMBERSHIP (USERNAME,GROUPNAME) VALUES ('hr1','hr');
INSERT INTO OS_MEMBERSHIP (USERNAME,GROUPNAME) VALUES ('manager1','manager');


我的流程定义文件为: leave_apply.xml

<?xml version="1.0" encoding="GBK"?><!DOCTYPE workflow PUBLIC "-//OpenSymphony Group//DTD OSWorkflow 2.6//EN" "http://www.opensymphony.com/osworkflow/workflow_2_8.dtd"><workflow><initial-actions><action id="100" name="启动请假申请工作流"><results><unconditional-result old-status="Finished"status="Underway" step="1" /></results></action></initial-actions><steps><step id="1" name="请假申请"><actions><action id="1" name="提交需求申请"><restrict-to><conditions type="AND"><condition type="class"><arg name="class.name">com.opensymphony.workflow.util.OSUserGroupCondition</arg><arg name="group">employee</arg></condition></conditions></restrict-to><pre-functions><function type="class"><arg name="class.name">com.osworkflow.leave.ApplyFunction</arg></function></pre-functions><results><result old-status="Finished" status="Underway"step="2" owner="manager1"><conditions type="AND"><condition type="beanshell"><arg name="script">propertySet.getInt("dayCount")>3</arg></condition></conditions><post-functions><function type="beanshell"><arg name="script">System.out.println("步骤 1 提交需求申请满足条件结果 需部门经理审批...");</arg></function></post-functions></result><unconditional-result old-status="Finished"status="Underway" step="3" owner="hr1" /></results></action></actions></step><step id="2" name="请假申请审核"><actions><action id="2" name="部门主管审批请假申请"><restrict-to><conditions type="AND"><condition type="beanshell"><arg name="script">true</arg></condition><condition type="class"><arg name="class.name">com.opensymphony.workflow.util.StatusCondition</arg><arg name="status">Underway</arg></condition><condition type="class"><arg name="class.name">com.opensymphony.workflow.util.OSUserGroupCondition</arg><arg name="group">manager</arg></condition></conditions></restrict-to><pre-functions><function type="class"><arg name="class.name">com.osworkflow.leave.ApproveFunction</arg></function></pre-functions><results><result old-status="Finished" status="Underway"step="5"><conditions type="AND"><condition type="beanshell"><arg name="script">propertySet.getInt("opinion")==2</arg></condition></conditions><post-functions><function type="beanshell"><arg name="script">System.out.println("步骤 2 请假申请审核部门经理审批没有通过 ...");</arg></function></post-functions></result><unconditional-result old-status="Finished"status="Underway" step="3" owner="hr1" /></results></action></actions></step><step id="3" name="请假申请审核"><actions><action id="3" name="人力资源主管审批请假申请"><pre-functions><function type="class"><arg name="class.name">com.osworkflow.leave.ApproveFunction</arg></function></pre-functions><results><result old-status="Finished" status="Underway"step="5"><conditions type="AND"><condition type="beanshell"><arg name="script">propertySet.getInt("opinion")==2</arg></condition></conditions></result><unconditional-result old-status="Finished"status="Underway" step="5" /></results></action></actions></step><step id="4" name="请假申请结果通知"><actions><action id="4" auto="true" name="请假申请获准邮件通知"><pre-functions><function type="beanshell"><arg name="script">System.out.println("步骤 4 自动动作 请假申请获准邮件通知Send mail 祝贺你");</arg></function></pre-functions><results><unconditional-result old-status="Finished"status="Finished" step="6" /></results></action></actions></step><step id="5" name="请假申请结果通知"><actions><action id="5" auto="true" name="请假申请没能获准邮件通知"><pre-functions><function type="beanshell"> <arg name="script">System.out.println("步骤 5 自动动作 请假申请未获准邮件通知Send mail ");</arg> </function></pre-functions><results><unconditional-result old-status="Finished" status="Finished" step="6" /></results></action></actions></step><step id="6" name="flow over"></step></steps></workflow>


osworkflow.xml文件为:

<osworkflow><persistence class="com.opensymphony.workflow.spi.jdbc.MySQLWorkflowStore"> <property key="datasource" value="jdbc/osworkflow"/>   <property key="step.sequence.increment"value="INSERT INTO OS_STEPIDS (ID) values (null)"/>    <property key="step.sequence.retrieve"   value="SELECT count(ID) FROM OS_STEPIDS"/>    <property key="entry.sequence.increment" value="INSERT INTO OS_ENTRYIDS (ID) values (null)"/>    <property key="entry.sequence.retrieve"value="SELECT count(ID) FROM OS_ENTRYIDS"/>    <property key="entry.table" value="OS_WFENTRY"/> <property key="entry.id" value="ID"/> <property key="entry.name" value="NAME"/> <property key="entry.state" value="STATE"/><property key="history.table" value="OS_HISTORYSTEP"/> <property key="current.table" value="OS_CURRENTSTEP"/> <property key="historyPrev.table" value="OS_HISTORYSTEP_PREV"/> <property key="currentPrev.table" value="OS_CURRENTSTEP_PREV"/> <property key="step.id" value="ID"/> <property key="step.entryId" value="ENTRY_ID"/> <property key="step.stepId" value="STEP_ID"/> <property key="step.actionId" value="ACTION_ID"/> <property key="step.owner" value="OWNER"/> <property key="step.caller" value="CALLER"/> <property key="step.startDate" value="START_DATE"/> <property key="step.finishDate" value="FINISH_DATE"/> <property key="step.dueDate" value="DUE_DATE"/> <property key="step.status" value="STATUS"/> <property key="step.previousId" value="PREVIOUS_ID"/>   </persistence><factory class="com.opensymphony.workflow.loader.XMLWorkflowFactory"><property key="resource" value="workflows.xml"/> </factory></osworkflow>



默认的项目界面:default.jsp
<%@ page import="com.opensymphony.util.TextUtils"%><%@ page contentType="text/html;charset=GBK"%><meta http-equiv="Content-Type" content="text/html; charset=GBK" /> <html>    <head>      <title>OSWorkflow Example App</title>    </head>    <body>    <p>    请假申请管理系统    <form method="POST" action="myprocess/login.jsp">    <table border="0">      <tr><td>用户名:</td><td><input type="text" name="username"></td></tr>      <tr><td>密码:</td><td><input type="password" name="password"></td></tr>      <tr><td colspan="2"><input type="submit" value=" 登陆 "></td></tr>    </table>    </form>    <hr>    </body></html>


login.jsp代码:

<%@ page import="com.opensymphony.user.UserManager,               com.opensymphony.user.EntityNotFoundException"%><%    String username = request.getParameter("username");    String password = request.getParameter("password");    System.out.println("=================username:" + username);    System.out.println("=================password:" + password);      UserManager um = UserManager.getInstance();      boolean authenticated = true;    if (authenticated) {      session.setAttribute("username", username);      response.sendRedirect("nav.jsp");    } else {      response.sendRedirect("../default.jsp?auth_failed=true");    }%>


nav.jsp代码:

<%@ page contentType="text/html;charset=GBK"%><meta http-equiv="Content-Type" content="text/html; charset=GBK" /><hr><a href="default.jsp">首页</a> |<a href="leaveApply.jsp">申请请假</a> | <a href="underway.jsp">处理请假申请</a>

leaveApply.jsp代码:

<%@ page import="com.opensymphony.util.TextUtils"%><%@ page contentType="text/html;charset=GBK"%><meta http-equiv="Content-Type" content="text/html; charset=GBK" /> <html>    <head>      <title>OSWorkflow Example App</title>    </head>    <body>    <p>    请假申请,请填写下面请假申请单    <form method="POST" action="leaveApplyCreate.jsp">    <table border="0">      <tr><td>请假原因:</td><td><input type="text" name="reason"></td></tr>      <tr><td>请假天数:</td><td><input type="text" name="dayCount"> 整数</td></tr>      <tr><td colspan="2"><input type="submit" value="提交申请"></td></tr>    </table>    </form>    <hr>    </body></html>


leaveApplyCreate.jsp代码:

<%@ page import="java.util.*,               com.opensymphony.user.UserManager,               com.opensymphony.user.EntityNotFoundException,               com.opensymphony.workflow.Workflow,               com.opensymphony.workflow.config.DefaultConfiguration,               com.opensymphony.workflow.basic.BasicWorkflow"%><%@ page contentType="text/html;charset=GBK"%><%    String reason = request.getParameter("reason");    int dayCount = Integer.parseInt((String)request.getParameter("dayCount"));    String applicant = (String)session.getAttribute("username");      System.out.println("=======从页面得到的数据:=====");    System.out.println("reason: " + reason);    System.out.println("dayCount: " + dayCount);    System.out.println("applicant: " + applicant);            Workflow wf = new BasicWorkflow((String) session.getAttribute("username"));    DefaultConfiguration config1 = new DefaultConfiguration();    wf.setConfiguration(config1);      Map map = new HashMap();    map.put("applicant", applicant);    map.put("reason", reason);    map.put("dayCount", new Integer(dayCount));             System.out.println("放进map的值" );    System.out.println("========= map.applicant:" + map.get("applicant") );    System.out.println("========= map.reason:" + map.get("reason") );    System.out.println("========= map.dayCount:" + map.get("dayCount") );            try {      long wfid = wf.initialize("leave", 100, null);                  wf.doAction(wfid, 1, map);      out.print("请假申请已经成功提交,请等待审批!");    } catch (Exception ex){      //out.print("提交请假申请时出现异常,可能没有增加您提交需求的权限!");             ex.printStackTrace();    }%><%@ include file="nav.jsp" %>

当执行到 long wfid = wf.initialize("leave", 100, null);这一句的时候,tomcat报出如下错误:


com.opensymphony.workflow.StoreException: Unable to create current step for work
flow instance #3: root cause: Cannot add or update a child row: a foreign key co
nstraint fails (`osworkflow`.`os_currentstep`, CONSTRAINT `os_currentstep_ibfk_2
` FOREIGN KEY (`OWNER`) REFERENCES `os_user` (`USERNAME`))
      at com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore.createCurrentSte
p(JDBCWorkflowStore.java:166)
      at com.opensymphony.workflow.AbstractWorkflow.createNewCurrentStep(Abstr
actWorkflow.java:1509)
      at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(Abstrac
tWorkflow.java:1256)
      at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflo
w.java:618)
      at org.apache.jsp.myprocess.leaveApplyCreate_jsp._jspService(leaveApplyC
reate_jsp.java:87)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:324)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2
92)


请问哥们儿们,为什么会有外键约束冲突呢,我的数据库表os_user和os_group、os_memership里有对应的流程定义的owner和caller啊,郁闷了好几天了,在线等,谢谢啊
页: [1]
查看完整版本: 请大家帮我看看到底应该怎么修改