<?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>Data versioning - writing to two tables in a single transaction</title><link>https://community.appian.com/discussions/f/data/13491/data-versioning---writing-to-two-tables-in-a-single-transaction</link><description>Hello, 
 Generally the question, is best way to do versioning with Appian on to DB? 
 We are considering the following approach for implementation. Have a single table, which stores versions of data in the same table. Example, if row {id:&amp;#39;1&amp;#39;,name:&amp;quot;test</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Data versioning - writing to two tables in a single transaction</title><link>https://community.appian.com/thread/61240?ContentTypeID=1</link><pubDate>Fri, 05 Oct 2018 14:38:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:be427336-a058-491a-90a4-9799486748de</guid><dc:creator>harishn</dc:creator><description>&lt;p&gt;&lt;a href="/members/harrisont606"&gt;harrisont606&lt;/a&gt;&amp;nbsp;and @shanmukha Thanks for the reply, infact I wanted to go with triggers, but we can not use triggers in current implementation.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="/members/harishkumart"&gt;harishkumart&lt;/a&gt;&amp;nbsp;and &lt;a href="/members/sivac0001"&gt;Siva&lt;/a&gt;&amp;nbsp;Thanks for the reply,&amp;nbsp;I am not sure how I can achieve this with the @Version annotation. My understanding is that it only provides optimistic lock and do not save the old verison of the object within the table. I tried testing using a simple process.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As &lt;a href="/members/sivac0001"&gt;Siva&lt;/a&gt;&amp;nbsp;you have mentioned, we may go in the approach of one single table that has both audit and transaction data, and update and insert rows on each update - update old existing row as old and insert new row.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My understanding is that it would be best to be done in one single transaction/ single step, now I have a sub process which has checks and replicates data for updates and insert. Doing this seems the way to go.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Data versioning - writing to two tables in a single transaction</title><link>https://community.appian.com/thread/61229?ContentTypeID=1</link><pubDate>Fri, 05 Oct 2018 13:29:55 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b126e90f-0a35-4c4b-987c-0dafa7a7e8df</guid><dc:creator>harrisont606</dc:creator><description>If you go ahead with triggers, try to keep them as simple as possible. If you google &amp;quot;mysql trigger best practices&amp;quot; you will see lots of articles cautioning against using them.  Complicated triggers have two issues:&lt;br /&gt;
&lt;br /&gt;
1) They can hurt performance when writing to the table. If you plan to do many inserts to this table, the triggers will fire on each one.&lt;br /&gt;
&lt;br /&gt;
2) The logic is somewhat hidden from your front end developers who many not be aware the triggers exist or even know how to check for them. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
That said, IMO triggers can be a good tool for your use case. As obscure as a trigger can be, expecting the dev team to just remember to update the history table every time they update the main table is asking for trouble.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Data versioning - writing to two tables in a single transaction</title><link>https://community.appian.com/thread/61210?ContentTypeID=1</link><pubDate>Fri, 05 Oct 2018 04:13:35 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ae8f1b80-238e-4af9-80ff-168bbb1c0545</guid><dc:creator>Shanmukha</dc:creator><description>Hi Harish,&lt;br /&gt;
&lt;br /&gt;
I agree with @Shiva approach. Instead of creating this in the upfront, you can try use the trigger on the table. This could be very easy and can give faster results instead of writing same data in the two different tables (transaction, audit table). This way with one single update it will also insert the record in the audit table in the background.&lt;br /&gt;
&lt;br /&gt;
Hope this may help..&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Data versioning - writing to two tables in a single transaction</title><link>https://community.appian.com/thread/61209?ContentTypeID=1</link><pubDate>Fri, 05 Oct 2018 04:06:46 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ff362afc-2249-424a-aeda-11b40fa0d553</guid><dc:creator>vishnuv</dc:creator><description>Hi,&lt;br /&gt;
There is a similar post which might help --&amp;gt; &lt;a href="https://community.appian.com/discussions/f/data/11093/multiple-sql-commands-for-a-single-insert/48631#48631"&gt;community.appian.com/.../48631&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Thanks.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Data versioning - writing to two tables in a single transaction</title><link>https://community.appian.com/thread/61207?ContentTypeID=1</link><pubDate>Fri, 05 Oct 2018 02:59:14 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f18de451-8b94-496a-bf18-06b7c0d9bd5a</guid><dc:creator>Siva</dc:creator><description>&lt;p&gt;Hi Harish,&lt;/p&gt;
&lt;p&gt;AFAIK , Maintain 2 tables one for&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1)Transactional data&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2)Audit history.&lt;/p&gt;
&lt;p&gt;For Insert write to Transnational and for update write to Audit(You can write insert &amp;amp; update request as well depending on the requirement), So that you can easily track it.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you want to track the Versioning of each field, you can simply add @Version annotation to the specific field in XSD.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I hope this might help for your requirement.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Siva Chimata&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Data versioning - writing to two tables in a single transaction</title><link>https://community.appian.com/thread/61204?ContentTypeID=1</link><pubDate>Fri, 05 Oct 2018 02:33:53 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:65f441d0-1bb5-414f-988d-03fe40924c98</guid><dc:creator>harishkumart</dc:creator><description>Hi Harishn,&lt;br /&gt;
I understand that you wanted to have the versioning on the database rows. If this is the requirement that you are trying to achieve you can do this by adding @Version annotation on the version field in the xsd. This will automatically save the version for each record . Please let me know if your requiremnet is something else so as to be able to provide you with better solution.&lt;br /&gt;
Hope this helps!&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>