These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: deleted object would be re-saved by cascade
PostPosted: Mon Sep 11, 2006 1:53 am 
Newbie

Joined: Mon Sep 11, 2006 1:29 am
Posts: 4
Hi guys. I am having a problem in deleting a table

the error was


net.sf.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations):
369, of class: com.oakgrovesystems.reactor.processMediation.hibernate.HibConditionalChange



this happens when I flush the session....

I am deleting the process table(HibProcess)

here the mapping for process table


Code:
  <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 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>


now here for the ConditionalChanges table( HibConditionalChanges)

Code:
   <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>



I tried deleting the HibConditionalChange
which is connected relationship to the HibProcess..

hope I put enough info here..


thanks in advance..


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 11, 2006 4:20 am 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
1. Please post your complete mapping in future questions.
2. To delete a Process:
a. Make sure your Process is not associated to any parent.
b. Delete the Process and all connected ConditionalChange will be too.
3. To delete a ConditionalChange:
a. Remove the ConditionalChange from the Sets from all Processes asigned to.
b. Save the Process which had the ConditionalChange and the ConditionalChange will be vanished too. (There is no need to delete it explicit.)

4. Don't forget to credit me if this helped to understand.


Top
 Profile  
 
 Post subject: As requested
PostPosted: Mon Sep 11, 2006 6:04 am 
Newbie

Joined: Mon Sep 11, 2006 1:29 am
Posts: 4
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>

HibConditonalChanges

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.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 codes
Code:
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 method
Code:
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 11, 2006 6:08 am 
Newbie

Joined: Mon Sep 11, 2006 1:29 am
Posts: 4
let me rephrase that
the error there some thing connected to HibConditionalchanges right?
all I have to remove all connected HibConditionalchanges and set hibprocess.setConditionalchanges(null);

thanks for the answer... I am still having same error


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 12, 2006 6:04 am 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
Mistake 1: Don't flush the session in disassociate before you finished your deletion process.

Mistake 2: As I already said, you don't need to disassociate all HibConditionalChanges because these will be delete automatically since you already set "all-delete-orphan".


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 12, 2006 6:30 am 
Newbie

Joined: Mon Sep 11, 2006 1:29 am
Posts: 4
sorry about that there's no session.flush(); on disassociate(child, session); I just tried it out... actually the only
session.flush(); is in delete method hopefully I remove it all...

thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.