How to delete child table records during the update of parent table using Hibernate -


I have a connection with several parent table A and hair table B, C.

Let's say I have the data, in the original key 1, there are 3 rows in the child's table B in the original table 1 and 4 rows in the child's table.

Now if I want to delete the rows in the table during a child update to the parent table (which means that now, I want to update the table with only one line in each row and Remove other rows in them), how to handle this scenario in hibernation?

Update

First of all, sorry that my question was unclear. Here are more details of this.

I have a parent's table policy

 . "Policy" ( "POLICY_OID" numbers enable zero CREATE TABLE "DEV2" (38,0) to "CREATED_DATE" TIMESTAMP (0) not able NULL, "EFFECTIVE_DATE" TIMESTAMP (0), "UPDATED_DATE" TIMESTAMP (0), "status" VARCHAR2 (32 bytes), interrupt enable "PK128" primary key ( "POLICY_OID") barrier "REFPOLICY_CLASS290" foreign key ( "POLICY_CLASS") reference "DEV2". "POLICY_CLASS" ( "POLICY_CLASS_REF"))  

and the child table @OneToMany relationship POLICY_RELATIONSHIP

  ( "POLICY_RELATIONSHIP_OID" number table "DEV2". "POLICY_RELATIONSHIP" (38,0) not able NULL, "POLICY_ACTOR "Number (38,0) No NULL enabled," POLICY_ACTOR_TYPE "VARCHAR2 (32 bytes)" PK156 " Rathamik key ( "POLICY_LATIONSHIP_OID"), CONSTRAINT "REFPOLICY338" foreign key ( "POLICY_OID") Reference "DEV2". "Policy" ( "POLICY_OID") enabled)  

For example, I For example, sample data is something to do.

  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  

If I try to apply change for policy object 1234 and UPDATED_DATE 2010-06-15 and PolicyRelationship is the data like below

  POLICY_RELATIONSHIP_OID POLICY_ACTOR POLICY_ACTOR_TYPE POLICY_OID tap George Primary user 1234  

what three rows Tanna, which already exists in the PolicyRelation table and insert a new row .. New data with

Please let me know that my problem is still not clear that

my environment:.

Java 1.6, Hibernate 3.5, JBoss

In this Java code, and If if your mapping will be correct ev are Erything right you are using cascade "save-update" of some kind, or something like that all 'your code:

  policy.getPolicyRelationships (). clear (); Policy relay PR = new policy related relationship (); ... pr.setParent (policy); . Policy.getPolicyRelationships () (public relations) add; Dao.save (policy);  

Or overwrite existing values ​​with the values ​​you want.

  policy.getPolicyRelationships (). clear (); Set up & lt; PolicyRelationship & gt; PrSet = new tree set & lt; Policy Relabel & gt; (); Policy relay PR = new policy related relationship (); PrSet.add (public relations); ... pr.setParent (policy); Policy.setPolicyRelationships (prSet); Dao.save (policy);  

Alternatively, you can set the relationship to use cascade = "all-delete-orphan", which means that those children should be hibernate, When they lose reference to a parent unit. If you want to remove the policy, then it is relevant, then the policy relations will also be removed from the DB.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -