<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Creating a Parent and Child at once in a One-to-Many relationship</title><link>https://community.appian.com/discussions/f/data/14157/creating-a-parent-and-child-at-once-in-a-one-to-many-relationship</link><description>I have been messing around with nested CDTs recently, in particular One-to-Many Master-Detail relationships. This is maintained on the database level via a foreign key on the child table. An example structure is shown below: 
 CREATE TABLE `Parent`( </description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Creating a Parent and Child at once in a One-to-Many relationship</title><link>https://community.appian.com/thread/64761?ContentTypeID=1</link><pubDate>Tue, 19 Feb 2019 18:22:53 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:66b0cd8d-da44-407e-aabf-10c7a5178364</guid><dc:creator>Larry Nguyen</dc:creator><description>&lt;p&gt;I was able to get this to work two ways: &lt;br /&gt; &lt;br /&gt; One way was to make the parent cdt refer to the child cdt (nested cdt) and setup a JOIN COLUMN for the list of child cdt. Unfortunately, doing it this way involves removing the parentId NOT NULL constraint because of the way Hibernate does things under the hood. Hibernate will write the parent entry first, the child entries without a foreign key entry next, and finally it will update the child entries to the correct parent id reference. This sequence will fail with the non-null constraint. You can read more about this scenario and Hibernate &lt;a href="https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate/"&gt;here&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt; The second way I got this to work was to have the child cdt refer to the parent cdt (another nested cdt). I also had to make sure the cascade type was ALL in the child CDT&amp;#39;s reference to the parent CDT. Then in the process, the parent CDT has to be prepped and the child CDT has to refer to the parent CDT. The write to datastore will be using the child data store entity.&lt;br /&gt; &lt;br /&gt; Hope this helps.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>