Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to delete child table records during the update of parent table using Hibernate
    text
    copied!<p>I have a Parent Table A and child tables B,C with many to one relations.</p> <p>Lets say I have data like, for primary key 1 in parent table A I have 3 rows in child table B and 4 rows in child table C.</p> <p>Now if I want to delete the rows of the child table during an update of the parent table(that means Now, I want to update the table only with one row in each child tables and delete the other rows in them) then how to handle this scenario in hibernate?</p> <p><strong>Update</strong></p> <p>Firstly, sorry that my question was unclear. Here are more details of it.</p> <p>I have a parent table Policy</p> <pre><code>CREATE TABLE "DEV2"."POLICY" ( "POLICY_OID" NUMBER(38,0) NOT NULL ENABLE, "CREATED_DATE" TIMESTAMP (0) NOT NULL ENABLE, "EFFECTIVE_DATE" TIMESTAMP (0), "UPDATED_DATE" TIMESTAMP (0), "STATUS" VARCHAR2(32 BYTE), CONSTRAINT "PK128" PRIMARY KEY ("POLICY_OID") , CONSTRAINT "REFPOLICY_CLASS290" FOREIGN KEY ("POLICY_CLASS") REFERENCES "DEV2"."POLICY_CLASS" ("POLICY_CLASS_REF") ENABLE ) </code></pre> <p>and @OneToMany relation to child table POLICY_RELATIONSHIP</p> <pre><code>CREATE TABLE "DEV2"."POLICY_RELATIONSHIP" ( "POLICY_RELATIONSHIP_OID" NUMBER(38,0) NOT NULL ENABLE, "POLICY_ACTOR" NUMBER(38,0) NOT NULL ENABLE, "POLICY_ACTOR_TYPE" VARCHAR2(32 BYTE) NOT NULL ENABLE, "POLICY_OID" NUMBER(38,0) NOT NULL ENABLE, CONSTRAINT "PK156" PRIMARY KEY ("POLICY_RELATIONSHIP_OID") , CONSTRAINT "REFPOLICY338" FOREIGN KEY ("POLICY_OID") REFERENCES "DEV2"."POLICY" ("POLICY_OID") ENABLE) </code></pre> <p>For Example, I have the sample data something like this.</p> <pre><code>POLICY_OID CREATED_DATE EFFECTIVE_DATE STATUS UPDATED_DATE 1234 06/14/2020 06/14/2010 active 06/14/2010 POLICY_RELATIONSHIP_OID POLICY_ACTOR POLICY_ACTOR_TYPE POLICY_OID 98765 John Primary User 1234 98766 Bill Secondary User 1234 98767 Mary Intermediate User 1234 </code></pre> <p>If I try to persist the Policy Object 1234 and UPDATED_DATE changed to 06/15/2010 and the PolicyRelationship has data like below</p> <pre><code>POLICY_RELATIONSHIP_OID POLICY_ACTOR POLICY_ACTOR_TYPE POLICY_OID null George Primary User 1234 </code></pre> <p>Is there any possible way with hibernate, to delete the three rows which already exist in the PolicyRelation table and insert an new row with new Data.</p> <p>Please let me know if my problem is still unclear.</p> <p>My Environment:</p> <p>Java 1.6, Hibernate 3.5, JBoss.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload