<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: How to delete a dependent persistence object?</title><link>https://answers.axonivy.com/questions/1371/how-to-delete-a-dependent-persistence-object</link><description>&lt;p&gt;We have a persistence object A which has a property &lt;code&gt;List(Object b)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When we remove one object b from the list with:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;out.questionnaireConcept.QuestionnaireConceptParticpants.remove(in.participantToRemove);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and then try to persist this with:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ivy.persistence.***MuPersistence.merge(in.questionnaireConcept);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The participant which we tried to remove is still present in the database. I thought this could be set within the persistence definition in this window:&lt;/p&gt;
&lt;p&gt;&lt;img alt="alt text" src="http://answers.axonivy.com/upfiles/Unbenannt_6vIaC2d.PNG"&gt;&lt;/p&gt;
&lt;p&gt;Do we have to remove the object b separately from the database or how can we achieve this?&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/1371/how-to-delete-a-dependent-persistence-object" rel="self"></atom:link><language>en</language><lastBuildDate>Tue, 23 Jun 2015 11:44:45 -0400</lastBuildDate><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/1371/how-to-delete-a-dependent-persistence-object/1377</link><description>&lt;p&gt;To have this feature working you need to set an additional property on the participant List field which is not accessible from the UI: &lt;em&gt;orphanRemoval=true&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You can set the property as follows: switch into the Java Perspective -&amp;gt; right click on the generated entity data class in src_dataClasses -&amp;gt; open with -&amp;gt; java editor. Find the line where the List&amp;lt;?&amp;gt; (participants) is declared. Add the orphanRemoval property. &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  @javax.persistence.OneToMany(cascade={javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.MERGE, javax.persistence.CascadeType.REMOVE, javax.persistence.CascadeType.REFRESH}, fetch=javax.persistence.FetchType.EAGER, mappedBy="organisation", orphanRemoval=true)
  private java.util.List&amp;lt;ch.monokellabs.crm.db.OrganisationPhone&amp;gt; phones;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As soon as you're typing something in the Java Editor you have to press ok on the prompt that informs that you're editing a derrived resource. This means that whenever you edit the DataClass with the UI editor, you're changes will be overwritten. So for long term it could make more sense to copy the whole java class into your normal java source code and delete the DataClass.&lt;/p&gt;
&lt;p&gt;Further informations to the orphanRemoval property can be found on stackoverflow: &lt;a href="http://stackoverflow.com/questions/4593241/jpa-removing-item-from-list"&gt;http://stackoverflow.com/questions/4593241/jpa-removing-item-from-list&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Tue, 23 Jun 2015 11:44:45 -0400</pubDate><guid>https://answers.axonivy.com/questions/1371/how-to-delete-a-dependent-persistence-object/1377</guid></item></channel></rss>