{"id":24220,"date":"2015-07-28T23:05:18","date_gmt":"2015-07-28T17:35:18","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=24220"},"modified":"2015-07-30T09:19:54","modified_gmt":"2015-07-30T03:49:54","slug":"perform-any-db-operation-in-an-isolated-transaction","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/perform-any-db-operation-in-an-isolated-transaction\/","title":{"rendered":"Perform any DB operation in an isolated transaction"},"content":{"rendered":"<p>Hi Friends,<\/p>\n<p>Sometimes we need to perform any DB operation in between a transaction, but due to transaction&#8217;s property, it&#8217;s getting committed only once the parent transaction will be finished.<\/p>\n<p>If you need to perform any operation that need to be committed immediately, irrespective of parent transaction (Example : for a dependent queuing operation etc.) like a isolated transactional operation, we can do so like this<\/p>\n<pre>org.hibernate.Session session = HibernateUtil.sessionFactory.openSession();\r\nTransaction tx = null;\r\ntry {\r\n   tx = session.beginTransaction();\r\n   \/\/Perform any DB operation in an Isolated Transaction here\r\n   object.save(flush: true);\r\n   tx.commit();\r\n}catch (Exception e) {\r\n   if (tx != null) tx.rollback();\r\n   e.printStackTrace();\r\n}finally {\r\n   session.close();\r\n}\r\n<\/pre>\n<p>If using grails we can do the same like this<\/p>\n<pre>DomainName.withTransaction { Transaction tx -&gt;\r\n \/\/Perform any DB operation in an Isolated Transaction here\r\n   object.save(flush: true);\r\n   tx.commit();\r\n}<\/pre>\n<p>Cheers !!!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi Friends, Sometimes we need to perform any DB operation in between a transaction, but due to transaction&#8217;s property, it&#8217;s getting committed only once the parent transaction will be finished. If you need to perform any operation that need to be committed immediately, irrespective of parent transaction (Example : for a dependent queuing operation etc.) [&hellip;]<\/p>\n","protected":false},"author":235,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2},"categories":[1],"tags":[4840,265,2051,1457,4844,2050,4841,1760],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/24220"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/235"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=24220"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/24220\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=24220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=24220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=24220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}