
    create table JBPM4_COMMENT (
        DBID_ bigint not null IDENTITY,
        CLASS_ varchar(255) not null,
        DBVERSION_ integer not null,
        USERID_ varchar(255),
        TIME_ datetime,
        MESSAGE_ varchar(255),
        PARENT_ bigint,
        PARENT_IDX_ integer,
        TASK_ bigint,
        TASK_IDX_ integer,
        primary key (DBID_)
    );

    create table JBPM4_DEPLOYMENT (
        DBID_ bigint not null IDENTITY,
        NAME_ text,
        TIMESTAMP_ bigint,
        STATE_ varchar(255),
        primary key (DBID_)
    );

    create table JBPM4_DEPLOYPROP (
        DBID_ bigint not null IDENTITY,
        DEPLOYMENT_ bigint,
        OBJNAME_ varchar(255),
        KEY_ varchar(255),
        STRINGVAL_ varchar(255),
        LONGVAL_ bigint,
        primary key (DBID_)
    );

    create table JBPM4_EXECUTION (
        DBID_ bigint not null IDENTITY,
        CLASS_ varchar(255) not null,
        DBVERSION_ integer not null,
        ACTIVITYNAME_ varchar(255),
        PROCDEFID_ varchar(255),
        HASVARS_ numeric(1,0),
        NAME_ varchar(255),
        KEY_ varchar(255),
        ID_ varchar(255) unique,
        STATE_ varchar(255),
        SUSPHISTSTATE_ varchar(255),
        PRIORITY_ integer,
        HISACTINST_ bigint,
        PARENT_ bigint,
        INSTANCE_ bigint,
        SUPEREXEC_ bigint,
        SUBPROCINST_ bigint,
        PARENT_IDX_ integer,
        primary key (DBID_)
    );

    create table JBPM4_HIST_ACTINST (
        DBID_ bigint not null IDENTITY,
        CLASS_ varchar(255) not null,
        DBVERSION_ integer not null,
        HPI_ varchar(255),
        TYPE_ varchar(255),
        EXECUTION_ varchar(255),
        ACTIVITY_NAME_ varchar(255),
        START_ datetime,
        END_ datetime,
        DURATION_ bigint,
        TRANSITION_ varchar(255),
        ASSIGNEE_ varchar(255),
        STATE_ varchar(255),
        primary key (DBID_)
    );

    create table JBPM4_HIST_PROCINST (
        ID_ varchar(255) not null,
        DBVERSION_ integer not null,
        PROCDEFID_ varchar(255),
        KEY_ varchar(255),
        START_ datetime,
        END_ datetime,
        DURATION_ bigint,
        STATE_ varchar(255),
        ENDACTIVITY_ varchar(255),
        primary key (ID_)
    );

    create table JBPM4_ID_GROUP (
        DBID_ bigint not null IDENTITY,
        DBVERSION_ integer not null,
        ID_ varchar(255),
        NAME_ varchar(255),
        TYPE_ varchar(255),
        PARENT_ bigint,
        primary key (DBID_)
    );

    create table JBPM4_ID_MEMBERSHIP (
        DBID_ bigint not null IDENTITY,
        DBVERSION_ integer not null,
        USER_ bigint,
        GROUP_ bigint,
        NAME_ varchar(255),
        primary key (DBID_)
    );

    create table JBPM4_ID_USER (
        DBID_ bigint not null IDENTITY,
        DBVERSION_ integer not null,
        ID_ varchar(255),
        PASSWORD_ varchar(255),
        GIVENNAME_ varchar(255),
        FAMILYNAME_ varchar(255),
        BUSINESSEMAIL_ varchar(255),
        primary key (DBID_)
    );

    create table JBPM4_JOB (
        DBID_ bigint not null IDENTITY,
        CLASS_ varchar(255) not null,
        DBVERSION_ integer not null,
        DUEDATE_ datetime,
        STATE_ varchar(255),
        ISEXCLUSIVE_ numeric(1,0),
        LOCKOWNER_ varchar(255),
        LOCKEXPTIME_ datetime,
        EXCEPTION_ text,
        RETRIES_ integer,
        PROCESSINSTANCE_ bigint,
        EXECUTION_ bigint,
        CFG_ bigint,
        SIGNAL_ varchar(255),
        EVENT_ varchar(255),
        REPEAT_ varchar(255),
        primary key (DBID_)
    );

    create table JBPM4_LOB (
        DBID_ bigint not null IDENTITY,
        DBVERSION_ integer not null,
        BLOB_VALUE_ varBinary(MAX),
        BINARY_VALUE_ binary(255),
        CLOB_VALUE_ text,
        TEXT_VALUE_ text,
        DEPLOYMENT_ bigint,
        NAME_ text,
        primary key (DBID_)
    );

    create table JBPM4_PARTICIPATION (
        DBID_ bigint not null IDENTITY,
        DBVERSION_ integer not null,
        GROUPID_ varchar(255),
        USERID_ varchar(255),
        TYPE_ varchar(255),
        TASK_ bigint,
        SWIMLANE_ bigint,
        primary key (DBID_)
    );

    create table JBPM4_SWIMLANE (
        DBID_ bigint not null IDENTITY,
        DBVERSION_ integer not null,
        NAME_ varchar(255),
        ASSIGNEE_ varchar(255),
        EXECUTION_ bigint,
        primary key (DBID_)
    );

    create table JBPM4_TASK (
        DBID_ bigint not null IDENTITY,
        CLASS_ char(1) not null,
        DBVERSION_ integer not null,
        NAME_ varchar(255),
        DESCR_ varchar(255),
        STATE_ varchar(255),
        SUSPHISTSTATE_ varchar(255),
        ASSIGNEE_ varchar(255),
        FORM_ varchar(255),
        PRIORITY_ integer,
        CREATE_ datetime,
        DUEDATE_ datetime,
        PROGRESS_ integer,
        SIGNALLING_ numeric(1,0),
        HASVARS_ numeric(1,0),
        SUPERTASK_ bigint,
        EXECUTION_ bigint,
        PROCINST_ bigint,
        SWIMLANE_ bigint,
        TASKDEFNAME_ varchar(255),
        primary key (DBID_)
    );

    create table JBPM4_VARIABLE (
        DBID_ bigint not null IDENTITY,
        CLASS_ varchar(255) not null,
        DBVERSION_ integer not null,
        KEY_ varchar(255),
        QUERYTEXT_ varchar(255),
        CONVERTER_ varchar(255),
        PROCINST_ bigint,
        DATE_VALUE_ datetime,
        DOUBLE_VALUE_ float(53),
        LONG_VALUE_ bigint,
        STRING_VALUE_ varchar(255),
        LOB_ bigint,
        EXECUTION_ bigint,
        EXESYS_ bigint,
        TASK_ bigint,
        primary key (DBID_)
    );

    alter table JBPM4_COMMENT 
        add constraint FKFD23139F86A745AD 
        foreign key (TASK_) 
        references JBPM4_TASK;

    create index IDX_DEPLPROP_DEPL on JBPM4_DEPLOYPROP (DEPLOYMENT_);

    alter table JBPM4_DEPLOYPROP 
        add constraint FK_DEPLPROP_DEPL 
        foreign key (DEPLOYMENT_) 
        references JBPM4_DEPLOYMENT;

    create index IDX_EXEC_SUPEREXEC on JBPM4_EXECUTION (SUPEREXEC_);

    create index IDX_EXEC_INSTANCE on JBPM4_EXECUTION (INSTANCE_);

    create index IDX_EXEC_SUBPI on JBPM4_EXECUTION (SUBPROCINST_);

    create index IDX_EXEC_PARENT on JBPM4_EXECUTION (PARENT_);

    alter table JBPM4_EXECUTION 
        add constraint FK_EXEC_PARENT 
        foreign key (PARENT_) 
        references JBPM4_EXECUTION;

    alter table JBPM4_EXECUTION 
        add constraint FK_EXEC_SUBPI 
        foreign key (SUBPROCINST_) 
        references JBPM4_EXECUTION;

    alter table JBPM4_EXECUTION 
        add constraint FK_EXEC_INSTANCE 
        foreign key (INSTANCE_) 
        references JBPM4_EXECUTION;

    alter table JBPM4_EXECUTION 
        add constraint FK_EXEC_SUPEREXEC 
        foreign key (SUPEREXEC_) 
        references JBPM4_EXECUTION;

    create index IDX_HAI_HPI on JBPM4_HIST_ACTINST (HPI_);

    alter table JBPM4_HIST_ACTINST 
        add constraint FK_HAI_HPI 
        foreign key (HPI_) 
        references JBPM4_HIST_PROCINST;

    create index IDX_GROUP_PARENT on JBPM4_ID_GROUP (PARENT_);

    alter table JBPM4_ID_GROUP 
        add constraint FK_GROUP_PARENT 
        foreign key (PARENT_) 
        references JBPM4_ID_GROUP;

    create index IDX_MEM_USER on JBPM4_ID_MEMBERSHIP (USER_);

    create index IDX_MEM_GROUP on JBPM4_ID_MEMBERSHIP (GROUP_);

    alter table JBPM4_ID_MEMBERSHIP 
        add constraint FK_MEM_GROUP 
        foreign key (GROUP_) 
        references JBPM4_ID_GROUP;

    alter table JBPM4_ID_MEMBERSHIP 
        add constraint FK_MEM_USER 
        foreign key (USER_) 
        references JBPM4_ID_USER;

    create index IDX_JOBRETRIES on JBPM4_JOB (RETRIES_);

    create index IDX_JOB_CFG on JBPM4_JOB (CFG_);

    create index IDX_JOB_PRINST on JBPM4_JOB (PROCESSINSTANCE_);

    create index IDX_JOB_EXE on JBPM4_JOB (EXECUTION_);

    create index IDX_JOBLOCKEXP on JBPM4_JOB (LOCKEXPTIME_);

    create index IDX_JOBDUEDATE on JBPM4_JOB (DUEDATE_);

    alter table JBPM4_JOB 
        add constraint FK_JOB_CFG 
        foreign key (CFG_) 
        references JBPM4_LOB;

    create index IDX_LOB_DEPLOYMENT on JBPM4_LOB (DEPLOYMENT_);

    alter table JBPM4_LOB 
        add constraint FK_LOB_DEPLOYMENT 
        foreign key (DEPLOYMENT_) 
        references JBPM4_DEPLOYMENT;

    create index IDX_PART_TASK on JBPM4_PARTICIPATION (TASK_);

    alter table JBPM4_PARTICIPATION 
        add constraint FK_PART_SWIMLANE 
        foreign key (SWIMLANE_) 
        references JBPM4_SWIMLANE;

    alter table JBPM4_PARTICIPATION 
        add constraint FK_PART_TASK 
        foreign key (TASK_) 
        references JBPM4_TASK;

    create index IDX_SWIMLANE_EXEC on JBPM4_SWIMLANE (EXECUTION_);

    alter table JBPM4_SWIMLANE 
        add constraint FK_SWIMLANE_EXEC 
        foreign key (EXECUTION_) 
        references JBPM4_EXECUTION;

    create index IDX_TASK_SUPERTASK on JBPM4_TASK (SUPERTASK_);

    alter table JBPM4_TASK 
        add constraint FK_TASK_SWIML 
        foreign key (SWIMLANE_) 
        references JBPM4_SWIMLANE;

    alter table JBPM4_TASK 
        add constraint FK_TASK_SUPERTASK 
        foreign key (SUPERTASK_) 
        references JBPM4_TASK;

    create index IDX_VAR_EXESYS on JBPM4_VARIABLE (EXESYS_);

    create index IDX_VAR_PROCINST on JBPM4_VARIABLE (PROCINST_);

    create index IDX_VAR_TASK on JBPM4_VARIABLE (TASK_);

    create index IDX_VAR_EXECUTION on JBPM4_VARIABLE (EXECUTION_);

    create index IDX_VAR_LOB on JBPM4_VARIABLE (LOB_);

    alter table JBPM4_VARIABLE 
        add constraint FK_VAR_PROCINST 
        foreign key (PROCINST_) 
        references JBPM4_EXECUTION;

    alter table JBPM4_VARIABLE 
        add constraint FK_VAR_LOB 
        foreign key (LOB_) 
        references JBPM4_LOB;

    alter table JBPM4_VARIABLE 
        add constraint FK_VAR_EXECUTION 
        foreign key (EXECUTION_) 
        references JBPM4_EXECUTION;

    alter table JBPM4_VARIABLE 
        add constraint FK_VAR_EXESYS 
        foreign key (EXESYS_) 
        references JBPM4_EXECUTION;

    alter table JBPM4_VARIABLE 
        add constraint FK_VAR_TASK 
        foreign key (TASK_) 
        references JBPM4_TASK;
