-->
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.  [ 1 post ] 
Author Message
 Post subject: How to Delete all child objects
PostPosted: Thu May 13, 2004 9:36 am 
Newbie

Joined: Thu May 13, 2004 9:24 am
Posts: 1
Hi,
I am new to hibernate, I have loved it as much as I have used it so far. I have a question.

I have table Organization and RollupStructure. Organization table defined all properties of Organization and Rollup structure defines the hierarchy of Organizations with

child_org_Id pk1 & fk to organization.Id
Parent_org_Id pk1 & fk to organization.Id
Rollup_type pk1

As u can see all three columns are part of composite primary key pk1 and child and parent id are foreign keys to Oraganization primary key.

Meaning a Organization can have a set of parent or child organizations.

Now I wanna be able to delete all child organization of parent organization and visa-versa. How do I do it.

If i set cascade="all-delete-orhpans"(exact name may differ) then I get error "No persister".

My question is can I not delete a set from a parent directly without have to delete individual items. And I am not deleting the parent here only all child table data pertaining to the parent.




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>
<!--
    Created by the Middlegen Hibernate plugin

    http://boss.bekk.no/boss/middlegen/
    http://hibernate.sourceforge.net/
-->

<class
    name="com.allegent.rbac.hibernate.Organization"
    table="ORGANIZATIONS"
>

    <id
        name="id"
        type="java.math.BigDecimal"
        column="ID"
    >
        <generator class="assigned" />
    </id>

    <property
        name="appropriationCode"
        type="java.lang.String"
        column="APPROPRIATION_CODE"
        length="30"
    />
    <property
        name="orgCode"
        type="java.lang.String"
        column="ORG_CODE"
        length="10"
    />
    <property
        name="fundingOffice"
        type="java.lang.String"
        column="FUNDING_OFFICE"
        length="350"
    />
    <property
        name="name"
        type="java.lang.String"
        column="NAME"
        unique="true"
        length="200"
    />
    <property
        name="status"
        type="java.lang.String"
        column="STATUS"
        length="240"
    />
    <property
        name="orgActivityType"
        type="java.lang.String"
        column="ORG_ACTIVITY_TYPE"
        not-null="true"
        length="30"
    />
    <property
        name="nickname"
        type="java.lang.String"
        column="NICKNAME"
        length="200"
    />
    <property
        name="description"
        type="java.lang.String"
        column="DESCRIPTION"
        length="4000"
    />
    <property
        name="sponsor"
        type="java.lang.String"
        column="SPONSOR"
        length="350"
    />
    <property
        name="notes"
        type="java.lang.String"
        column="NOTES"
        length="4000"
    />
    <property
        name="phoneCountryCode"
        type="java.lang.String"
        column="PHONE_COUNTRY_CODE"
        length="6"
    />
    <property
        name="phoneAreaCode"
        type="java.math.BigDecimal"
        column="PHONE_AREA_CODE"
        length="22"
    />
    <property
        name="phone"
        type="java.math.BigDecimal"
        column="PHONE"
        length="22"
    />
    <property
        name="phoneExtension"
        type="java.lang.String"
        column="PHONE_EXTENSION"
        length="240"
    />
    <property
        name="phoneInstructions"
        type="java.lang.String"
        column="PHONE_INSTRUCTIONS"
        length="240"
    />
    <property
        name="phoneType"
        type="java.lang.String"
        column="PHONE_TYPE"
        length="240"
    />
    <property
        name="street1"
        type="java.lang.String"
        column="STREET_1"
        length="240"
    />
    <property
        name="street2"
        type="java.lang.String"
        column="STREET_2"
        length="240"
    />
    <property
        name="city"
        type="java.lang.String"
        column="CITY"
        unique="true"
        length="240"
    />
    <property
        name="stateProv"
        type="java.lang.String"
        column="STATE_PROV"
        length="60"
    />
    <property
        name="country"
        type="java.lang.String"
        column="COUNTRY"
        length="80"
    />
    <property
        name="poBox"
        type="java.lang.String"
        column="PO_BOX"
        length="240"
    />
    <property
        name="poBoxZipcode"
        type="java.lang.String"
        column="PO_BOX_ZIPCODE"
        length="240"
    />
    <property
        name="zip"
        type="java.lang.String"
        column="ZIP"
        length="20"
    />
    <property
        name="postalcode"
        type="java.lang.String"
        column="POSTALCODE"
        length="240"
    />
    <property
        name="missionStatementUrl"
        type="java.lang.String"
        column="MISSION_STATEMENT_URL"
        length="2048"
    />
    <property
        name="homePage"
        type="java.lang.String"
        column="HOME_PAGE"
        length="2048"
    />
    <property
        name="processingStatus"
        type="java.lang.String"
        column="PROCESSING_STATUS"
        length="50"
    />
    <property
        name="lastStatusDate"
        type="java.sql.Timestamp"
        column="LAST_STATUS_DATE"
        length="7"
    />
    <property
        name="enteredBy"
        type="java.lang.String"
        column="ENTERED_BY"
        length="30"
    />
    <property
        name="enteredDate"
        type="java.sql.Timestamp"
        column="ENTERED_DATE"
        length="7"
    />
    <property
        name="emailId"
        type="java.lang.String"
        column="EMAIL_ID"
        length="240"
    />
    <property
        name="startDate"
        type="java.sql.Timestamp"
        column="START_DATE"
        length="7"
    />
    <property
        name="endDate"
        type="java.sql.Timestamp"
        column="END_DATE"
        length="7"
    />
    <property
        name="lastUpdated"
        type="java.sql.Timestamp"
        column="LAST_UPDATED"
        not-null="true"
        length="7"
    />
    <property
        name="lastUpdatedBy"
        type="java.lang.String"
        column="LAST_UPDATED_BY"
        not-null="true"
        length="30"
    />
    <property
        name="approvedBy"
        type="java.lang.String"
        column="APPROVED_BY"
        length="80"
    />
    <property
        name="approvalDate"
        type="java.sql.Timestamp"
        column="APPROVAL_DATE"
        length="7"
    />

    <!-- associations -->
    <!-- bi-directional one-to-many association to CustomPlatformCollection -->
    <!--set
        name="customPlatformCollections"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.CustomPlatformCollection"
        />
    </set-->
    <!-- bi-directional one-to-many association to RollupStructur -->
    <set
        name="rollupStructursByParentOrgId"
        lazy="true"
        inverse="true"
        cascade="all"
    >
        <key>
            <column name="PARENT_ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.RollupStructur"
        />
    </set>
    <!-- bi-directional one-to-many association to RollupStructur -->
    <set
        name="rollupStructursByChildOrgId"
        lazy="true"
        inverse="true"
        cascade="all"
    >
        <key>
            <column name="CHILD_ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.RollupStructur"
        />
    </set>
    <!-- bi-directional one-to-many association to RolesToOrganization -->
    <!-- set
        name="rolesToOrganizations"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.RolesToOrganization"
        />
    </set -->
    <!-- bi-directional one-to-many association to ResultSet -->
    <!--set
        name="resultSets"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.ResultSet"
        />
    </set-->
    <!-- bi-directional one-to-many association to DiscoveredNetwork -->
    <!--set
        name="discoveredNetworks"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.DiscoveredNetwork"
        />
    </set-->
    <!-- bi-directional one-to-many association to ReportFormat -->
    <!--set
        name="reportFormats"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.ReportFormat"
        />
    </set-->
    <!-- bi-directional one-to-many association to KnownNetwork -->
    <!--set
        name="knownNetworksByOrgIdIsOwnedBy"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID_IS_OWNED_BY" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.KnownNetwork"
        />
    </set-->
    <!-- bi-directional one-to-many association to KnownNetwork -->
    <!--set
        name="knownNetworksByOrgId"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.KnownNetwork"
        />
    </set-->
    <!-- bi-directional one-to-many association to EventsRecvd -->
    <!--set
        name="eventsRecvds"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.EventsRecvd"
        />
    </set-->
    <!-- bi-directional one-to-many association to User -->
    <set
        name="users"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.User"
        />
    </set>
    <!-- bi-directional one-to-many association to DbSchema -->
    <!--set
        name="dbSchemas"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.DbSchema"
        />
    </set-->
    <!-- bi-directional one-to-many association to ScorecardApproval -->
    <!--set
        name="scorecardApprovals"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.ScorecardApproval"
        />
    </set-->
    <!-- bi-directional one-to-many association to KnownNod -->
    <!--set
        name="knownNods"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.KnownNod"
        />
    </set-->
    <!-- bi-directional one-to-many association to ReportItemsApplicable -->
    <!--set
        name="reportItemsApplicables"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.ReportItemsApplicable"
        />
    </set-->
    <!-- bi-directional one-to-many association to Scorecard -->
    <!--set
        name="scorecardsByOrgId"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.Scorecard"
        />
    </set-->
    <!-- bi-directional one-to-many association to Scorecard -->
    <!--set
        name="scorecardsByOrgIdHighestApprovalFrom"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID_HIGHEST_APPROVAL_FROM" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.Scorecard"
        />
    </set-->
    <!-- bi-directional one-to-many association to SiteTailoring -->
    <!--set
        name="siteTailorings"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.SiteTailoring"
        />
    </set-->
    <!-- bi-directional one-to-many association to Comment -->
    <!--set
        name="comments"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.Comment"
        />
    </set-->
    <!-- bi-directional one-to-many association to AuditEvaluation -->
    <!--set
        name="auditEvaluations"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.AuditEvaluation"
        />
    </set-->
    <!-- bi-directional one-to-many association to Query -->
    <!--set
        name="queries"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.Query"
        />
    </set-->
    <!-- bi-directional one-to-many association to UserDevic -->
    <!--set
        name="userDevics"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.UserDevic"
        />
    </set-->
    <!-- bi-directional one-to-many association to ScoringCriteria -->
    <!--set
        name="scoringCriterias"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.ScoringCriteria"
        />
    </set-->
    <!-- bi-directional one-to-many association to DiscoveryPlan -->
    <!--set
        name="discoveryPlans"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.DiscoveryPlan"
        />
    </set-->
    <!-- bi-directional one-to-many association to EmpDomain -->
    <!--set
        name="empDomains"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="ORG_ID" />
        </key>
        <one-to-many
            class="com.allegent.rbac.hibernate.EmpDomain"
        />
    </set-->

</class>
</hibernate-mapping>



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>
<!--
    Created by the Middlegen Hibernate plugin

    http://boss.bekk.no/boss/middlegen/
    http://hibernate.sourceforge.net/
-->

<class
    name="com.allegent.rbac.hibernate.RollupStructur"
    table="ROLLUP_STRUCTURES"
>

    <composite-id name="comp_id" class="com.allegent.rbac.hibernate.RollupStructurPK">
        <key-property
            name="rollupType"
            column="ROLLUP_TYPE"
            type="java.lang.String"
            length="24"
        />
        <!-- bi-directional many-to-one association to Organization -->
        <key-many-to-one
           name="organizationByParentOrgId"
           class="com.allegent.rbac.hibernate.Organization"
       >
           <column name="PARENT_ORG_ID" />
       </key-many-to-one>
        <!-- bi-directional many-to-one association to Organization -->
        <key-many-to-one
           name="organizationByChildOrgId"
           class="com.allegent.rbac.hibernate.Organization"
       >
           <column name="CHILD_ORG_ID" />
       </key-many-to-one>
    </composite-id>   


    <!-- associations -->

</class>
</hibernate-mapping>


thanks a lot

Jay Hombal

_________________
Jay Hombal
Senior Software Engineer
Java,MCP,MCSD


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

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.