here the mapping of the 2 table
HiProcess
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class batch-size="10"
name="com.oakgrovesystems.reactor.processMediation.hibernate.HibProcess"
table="process"
dynamic-update="false"
dynamic-insert="false"
>
<cache usage="read-write" />
<id
name="realId"
column="realId"
type="java.lang.Long"
>
<generator class="native">
</generator>
</id>
<property
name="isDeleted"
type="boolean"
update="true"
insert="true"
column="isDeleted"
/>
<property
name="state"
type="int"
update="true"
insert="true"
column="state"
/>
<many-to-one
name="parent"
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibProcess"
cascade="none"
outer-join="auto"
update="true"
insert="true"
>
<column
name="parent"
index="process_parent_idx"
/>
</many-to-one>
<many-to-one
name="processDefinition"
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibProcess"
cascade="none"
outer-join="auto"
update="true"
insert="true"
>
<column
name="definition"
index="process_definition_idx"
/>
</many-to-one>
<many-to-one
name="rootProcess"
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibProcess"
cascade="none"
outer-join="auto"
update="true"
insert="true"
>
<column
name="rootProcess"
index="process_root_idx"
/>
</many-to-one>
<property
name="isRoot"
type="boolean"
update="true"
insert="true"
>
<column
name="isRoot"
index="process_isroot_idx"
/>
</property>
<property
name="description"
type="text"
update="true"
insert="true"
column="description"
/>
<property
name="isDefinition"
type="boolean"
update="true"
insert="true"
>
<column
name="isDefinition"
index="process_isdef_idx"
/>
</property>
<property
name="startDate"
type="java.lang.String"
update="true"
insert="true"
column="startDate"
/>
<property
name="endDate"
type="java.lang.String"
update="true"
insert="true"
column="endDate"
/>
<set batch-size="4"
name="subprocesses"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<cache
usage="read-write"
/>
<key
column="parent"
/>
<one-to-many
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibProcess"
/>
</set>
<set batch-size="4"
name="statuses"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<cache
usage="read-write"
/>
<key
column="process"
/>
<one-to-many
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibStatus"
/>
</set>
<set batch-size="4"
name="operands"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<cache
usage="read-write"
/>
<key
column="process"
/>
<one-to-many
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibOperand"
/>
</set>
<set batch-size="4"
name="policies"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<cache
usage="read-write"
/>
<key
column="process"
/>
<one-to-many
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibPolicy"
/>
</set>
<set batch-size="4"
name="ACL"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<cache
usage="read-write"
/>
<key
column="assignee"
/>
<one-to-many
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibProcessACE"
/>
</set>
<set batch-size="4"
name="currentStatuses"
table="process_currentstatus"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>
<cache
usage="read-write"
/>
<key
column="process"
/>
<many-to-many
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibStatus"
column="status"
outer-join="auto"
/>
</set>
<set batch-size="4"
name="conditionalChanges"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<cache
usage="read-write"
/>
<key
column="process"
/>
<one-to-many
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibConditionalChange"
/>
</set>
<set batch-size="4"
name="timerSpecs"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<cache
usage="read-write"
/>
<key
column="process"
/>
<one-to-many
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibTimerSpec"
/>
</set>
<map batch-size="4"
name="metadata"
table="processmetadata"
lazy="true"
sort="unsorted"
inverse="false"
cascade="all-delete-orphan"
>
<cache
usage="read-write"
/>
<key
column="process"
/>
<index
column="name"
type="string"
/>
<element
column="value"
type="text"
not-null="false"
unique="false"
/>
</map>
<map batch-size="4"
name="attributes"
table="processattributes"
lazy="true"
sort="unsorted"
inverse="false"
cascade="all-delete-orphan"
>
<cache
usage="read-write"
/>
<key
column="process"
/>
<index
column="name"
type="string"
/>
<element
column="value"
type="text"
not-null="false"
unique="false"
/>
</map>
<property
name="accessTag"
type="long"
update="true"
insert="true"
column="accessTag"
/>
<property
name="reactorObjectId"
type="java.lang.String"
update="true"
insert="true"
column="reactorObjectId"
not-null="true"
unique="true"
/>
<property
name="label"
type="java.lang.String"
update="true"
insert="true"
column="label"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-HibProcess.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
HibConditonalChangesCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class batch-size="10"
name="com.oakgrovesystems.reactor.processMediation.hibernate.HibConditionalChange"
table="conditionalChange"
dynamic-update="false"
dynamic-insert="false"
>
<cache usage="read-write" />
<id
name="realId"
column="realId"
type="java.lang.Long"
>
<generator class="native">
</generator>
</id>
<property
name="precondition"
type="boolean"
update="true"
insert="true"
column="precondition"
/>
<property
name="conditionType"
type="int"
update="true"
insert="true"
column="conditionType"
/>
<property
name="changeType"
type="int"
update="true"
insert="true"
column="changeType"
/>
<many-to-one
name="process"
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibProcess"
cascade="none"
outer-join="auto"
update="true"
insert="true"
>
<column
name="process"
index="conditionalchg_process_idx"
/>
</many-to-one>
<many-to-one
name="parent"
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibConditionalChange"
cascade="none"
outer-join="auto"
update="true"
insert="true"
>
<column
name="parent"
index="conditionalchange_parent_idx"
/>
</many-to-one>
<set batch-size="4"
name="subconditions"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<cache
usage="read-write"
/>
<key
column="parent"
/>
<one-to-many
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibConditionalChange"
/>
</set>
<many-to-one
name="conditionTargetProcess"
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibProcess"
cascade="none"
outer-join="auto"
update="true"
insert="true"
>
<column
name="conditionTargetProcess"
index="condchange_target_process_idx"
/>
</many-to-one>
<property
name="conditionTargetState"
type="int"
update="true"
insert="true"
column="conditionTargetState"
/>
<many-to-one
name="conditionTargetStatus"
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibStatus"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="conditionTargetStatus"
/>
<many-to-one
name="changeStatus"
class="com.oakgrovesystems.reactor.processMediation.hibernate.HibStatus"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="changeStatus"
/>
<property
name="changeState"
type="int"
update="true"
insert="true"
column="changeState"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-HibConditionalChange.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Java codesCode:
protected ServiceResponseObj delete(ServiceRequestObj request) {
if (!("process_object_delete").equals(request.getType())) {
return new ServiceResponseObj(Responses.CODE405_BAD_REQUEST_TYPE, "expected: process_object_delete +got: "
+ request.getType());
}
// Only accept deletes from PCS.
String sender = (String) request.getParameter("sender", String.class);
if (sender == null) {
return new ServiceResponseObj(Responses.CODE404_BAD_PARAMETERS, "no 'sender' parameter");
}
if (!sender.equals("ProcessCommandService")) {
return new ServiceResponseObj(Responses.CODE410_UNAUTHORIZED, "service denied");
}
// Get the type of object to be deleted.
Class type = (Class) request.getParameter("type", Class.class);
if (type == null) {
type = Object.class;
}
// get the id to be deleted. enforce mutex.
String id = (String) request.getParameter("id", String.class);
LabelPath lp = (LabelPath) request.getParameter("labelPath", LabelPath.class);
if ((id == null) && (lp == null)) {
return new ServiceResponseObj(Responses.CODE404_BAD_PARAMETERS,
"Request parameters did not contain an id or LabelPath for an object delete.");
}
if ((id != null) && (lp != null)) {
return new ServiceResponseObj(Responses.CODE404_BAD_PARAMETERS,
"Request parameters contained both an id and a LabelPath. "
+ "Specify one or the other; not both.");
}
Session session = null;
try {
session = openSession(new DeleteInterceptor());
if (id == null) {
// We need to resolve a labelpath to one id first.
if (isDebugEnabled()) {
debug("looking up id for LabelPath: " + lp);
}
boolean defsOnly = false;
if (request.getParameter("deleteDefinitionsOnly", Boolean.class) != null) {
defsOnly = ((Boolean) request.getParameter("deleteDefinitionsOnly", Boolean.class)).booleanValue();
}
// Look up the label.
Set ids = labelPathToIdSet(session, lp, type, defsOnly);
if (ids.size() == 0) {
// We're done.
return new ServiceResponseObj(Responses.CODE420_NOT_FOUND);
} else if (ids.size() > 1) {
// We're done.
return new ServiceResponseObj(Responses.CODE404_BAD_PARAMETERS, "The labelpath: " + lp.toString()
+ " resolves to more than one object.");
}
// We got a single id.
id = (String) ids.iterator().next();
}
// Call the real delete now.
boolean success = delete(session, id);
if (success) {
return new ServiceResponseObj(Responses.CODE200_OK);
} else {
return new ServiceResponseObj(Responses.CODE420_NOT_FOUND);
}
} catch (IdentifierMappingException e) {
log.error("Mapping problem in delete: ", e);
return new ServiceResponseObj(Responses.CODE500_INTERNAL_ERROR, e.getMessage());
} catch (ProcessObjectServiceException e) {
log.error("Hibernate error in labelpath resolution: ", e);
return new ServiceResponseObj(Responses.CODE500_INTERNAL_ERROR, e.getMessage());
} catch (HibernateException e) {
log.error("Hibernate error opening session in delete: ", e);
return new ServiceResponseObj(Responses.CODE500_INTERNAL_ERROR, e.getMessage());
} finally {
close(session);
}
}
delete methodCode:
protected boolean delete(Session session, String id) throws ProcessObjectServiceException {
if (isDebugEnabled()) {
debug("finding for id " + id);
}
HibMediationObject pmo = getExistingObject(id, session);
if (pmo == null) {
if (isDebugEnabled()) {
debug("could not find object for id " + id);
}
return false;
}
if (isDebugEnabled()) {
debug("found " + pmo + ", deleting");
}
try {
HibProcess p = pmo.getProcess();
if (p != null && p.isDefinition()) {
deleteDefinition(session, pmo);
} else {
if (pmo instanceof HibOperand) {
if (!p.isRoot())
p = p.getRootProcess();
updateProcessAttribute(p, pmo.getLabel(), session);
}
deleteInstance(session, pmo);
}
session.flush();
return true; // success
} catch (HibernateException e) {
ejbContext.setRollbackOnly();
log.error("error on delete attempt: ", e);
throw new ProcessObjectServiceException("Error on delete attempt: ", e);
}
}
deleteInstance(session, pmo); Code:
protected void deleteInstance(Session session, HibMediationObject pmo) throws HibernateException,
ProcessObjectServiceException {
// Since the parent/child relationships in LegaSuite BPM PMO's
// are cascading-save, we have to remove any object
// references held between this object and its parent, if
// it exists..
if (pmo instanceof HibProcess) {
HibProcess child = (HibProcess) pmo;
disassociate(child, session);
} else if (pmo instanceof HibStatus) {
HibStatus child = (HibStatus) pmo;
disassociate(child);
} else if (pmo instanceof HibOperand) {
HibOperand child = (HibOperand) pmo;
disassociate(child);
} else if (pmo instanceof HibPolicy) {
HibPolicy child = (HibPolicy) pmo;
disassociate(child);
}
session.delete(pmo);
}
disassociate(child, session);Code:
protected void disassociate(HibProcess process, Session session) throws ProcessObjectServiceException,
HibernateException {
HibProcess parent = process.getParent();
HibProcess root = process.getRootProcess();
// find all of the conditions which point to this process and remove them.
// GAF
//Session ses = openSession(new DeleteInterceptor());
List ref =session.find("from HibConditionalChange as change where change.conditionTargetProcess = ?",
process, Hibernate.entity(HibProcess.class));
Iterator i = ref.iterator();
// Set newhibConditiontarget = new HashSet();
while (i.hasNext()) {
HibConditionalChange chg = (HibConditionalChange) i.next();
session.delete(chg);
}
session.flush();
if (parent != null) {
// Break the link.
process.setParent(null);
parent.getSubprocesses().remove(process);
if (log.isDebugEnabled()) {
log.debug("Disassociated process " + process + " from parent before delete.");
}
}
// fix for not being able to delete instances on HSQL
if (process.getRealId() == root.getRealId()) {
if (log.isDebugEnabled()) {
log.debug("Disassociating root");
}
process.setRootProcess(null);
}
}
that about it
the error there some connected to HibConditionalchanges right?
all I have to remove all connected ConditionalChange and set hibprocess to null
thanks for the answer... I am still having same error