<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[OFB Tech - Medium]]></title>
        <description><![CDATA[Tech blog for OfBusiness (www.ofbusiness.com) - Medium]]></description>
        <link>https://medium.com/ofbusiness-tech?source=rss----8fba59e9597c---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>OFB Tech - Medium</title>
            <link>https://medium.com/ofbusiness-tech?source=rss----8fba59e9597c---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 02:11:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/ofbusiness-tech" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hibernate Issues Series : RollbackException]]></title>
            <link>https://medium.com/ofbusiness-tech/hibernate-issues-series-rollbackexception-94174bfce89b?source=rss----8fba59e9597c---4</link>
            <guid isPermaLink="false">https://medium.com/p/94174bfce89b</guid>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[rollbacks]]></category>
            <category><![CDATA[hibernate]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[exception]]></category>
            <dc:creator><![CDATA[Vijay Rawat]]></dc:creator>
            <pubDate>Tue, 05 Jun 2018 03:31:01 GMT</pubDate>
            <atom:updated>2018-06-05T03:31:01.490Z</atom:updated>
            <content:encoded><![CDATA[<p>This the first blog in my Hibernate Issues Series. In this piece, I will be introducing a few frequent and not-so-common issues relating to hibernate transactions.</p><p>Whenever we see this exception:</p><blockquote>javax.persistence.RollbackException: Transaction marked as rollbackOnly</blockquote><p>our default reaction is to search stackoverflow, mostly finding the solution as “using @Transactional’s noRollbackFor for CulpritException.class”</p><p><a href="#42fd">[Directly go to Caching the culprit section]</a></p><p>Today lets dive in and find how this exception is thrown by Spring framework.</p><p>We know that @org.springframework.transaction.annotation.Transactional is supported via aspects in spring using the <strong>proxy pattern</strong>.</p><p>You can check the spring wrapper <a href="https://gist.github.com/vijayrawatsan/753f2896d18fd982453a3c3b99867ffd">here</a> (<a href="https://gist.github.com/vijayrawatsan/753f2896d18fd982453a3c3b99867ffd">gist link</a>)<br>Essentially what it’s doing is :</p><ul><li>Creating a transaction around the method.</li><li>Invoke the method.</li><li>Handle exception.</li><li>Cleanup of resources.</li></ul><p>When @Transaction annotated method throw’s an exception, the control goes to <strong>TransactionAspectSupport#completeTransactionAfterThrowing(TransactionInfo txInfo, Throwable ex)</strong><br>Internally this method does the following:</p><ul><li>Checks if <strong>rollbackFor</strong> attribute is defined with <strong>@Transactional(rollbackFor = AnyException.class)</strong></li><li>If yes, then check if thrown exception is subclass of AnyException.class, in this case rollback the transaction.</li><li>If no, check if thrown exception is a subclass of RuntimeException or Error, in this case rollback the transaction.</li><li>If <strong>rollbackFor </strong>attribute is not present, check if thrown exception is a subclass of RuntimeException or Error, if yes rollback the transaction.</li><li>If we want to not rollback for a certain exception we can use <strong>noRollbackFor </strong>attribute.</li></ul><p>Now we know the theory lets see some code examples to corroborate our theory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6cce2305203ae5745e46d56ae9dff2a3/href">https://medium.com/media/6cce2305203ae5745e46d56ae9dff2a3/href</a></iframe><p>Lets see what’s happening in above examples.</p><p><strong>Example 1:</strong></p><p>In this example (<strong>UserService#createUserEx1()</strong>), we expect the transaction to commit because we are catching the exception thrown by exception service.</p><p>As per our theory, proxy will initialize the transaction, call this method, handles any caught exception, and then performs cleanup. Since this method(<strong>createUserEx1),</strong> catches the exception thrown by exception service. No exception reaches the proxy code and everything works as expected.</p><p><strong>Example 2:</strong></p><p>In this example (<strong>UserService#createUserEx2()</strong>) also, we expect the transaction to commit because we are catching the exception thrown by exception service.</p><p>This is a tricky example because, against our expectation, transaction rollbacks. So what’s happening?</p><ul><li>When we call <strong>createUserEx2() </strong>a transaction proxy(P1) is created, within which <strong>createUserEx2()</strong> method is called.</li><li>Call to <strong>throwExceptionTransactional</strong>() creates another transaction proxy(P2) is, within which <strong>throwExceptionTransactional()</strong> method is called. Since no <strong>propagation </strong>attribute is defined, same transaction will be forwarded for this method (lets call it <strong>T1</strong>).</li><li>There are 2 proxies but one transaction.</li><li>When <strong>throwExceptionTransactional() </strong>method throws exception, its proxy(P2) catches the transaction(<strong>T1</strong>), call the method to rollback it (basically sets the <strong>rollback flag to true</strong>), and re-throws the exception back in the chain.</li><li>Control returns to <strong>createUserEx2() </strong>method which catches the re-thrown exception.</li><li>The proxy(P1) of <strong>createUserEx2() </strong>method now tries to commit the transaction(T1) because of a clean exit from this method. But transaction T1 is already marked for rollback in P2 thus causing javax.persistence.RollbackException: Transaction marked as rollbackOnly</li></ul><p><strong>Example 3</strong></p><p>In example 3, <strong>createUserEx3() </strong>method looks almost same as <strong>createUserEx2() </strong>the only difference is the call to <strong>throwExceptionTransactionalRequiresNew() </strong>method which is a @Transactional annotated method with a special attribute propagation = Propagation.<em>REQUIRES_NEW (which creates a new transaction even if this method is called from a @</em>Transactional<em> </em>method<em>)</em></p><p>If you run this example, you will find that the code runs successfully without any exception. Why is that?</p><ul><li>When we call <strong>createUserEx3() </strong>a transaction proxy(P1) is created, within which <strong>createUserEx3()</strong> method is called.</li><li>Call to <strong>throwExceptionTransactionalRequiresNew</strong>() creates another transaction proxy(P2) is, within which <strong>throwExceptionTransactionalRequiresNew()</strong> method is called. Because of Propagation.<em>REQUIRES_NEW</em>, a new transaction will be created for this method as well (lets call it <strong>T2</strong>).</li><li>There are 2 proxies and 2 transactions.</li><li>When <strong>throwExceptionTransactionalRequiresNew() </strong>method throws exception, its proxy(P2) catches the transaction(<strong>T2</strong>), call the method to rollback it, and re-throws the exception back in the chain. (Transaction <strong>T2 </strong>is successfully rolled back after proxy P2 exits).</li><li>Control returns to <strong>createUserEx3() </strong>method which catches the re-thrown exception.</li><li>The proxy(P1) of <strong>createUserEx3() </strong>method is now successfully able to commit the transaction(T1) because of a clean exit from this method.</li></ul><p><strong>Example 4</strong></p><p>This example shows you how to avoid rollback in case of a specific exception using @Transacional attribute <strong>noRollbackFor. </strong>Using this attribute we can tell the transaction proxy to not rollback in case of a specific exception.</p><p><strong>Catching the culprit</strong></p><p>Above examples explains how can you craft your code in a way to avoid rollback exception. But when you run into javax.persistence.RollbackException: Transaction marked as rollbackOnly the stacktrace can only tell you which @Transactional method threw this exception but does not tell anything about the exception itself or where the actual exception is was thrown. How to find the source of exception then?</p><p>If you are still reading, you know where the proxy code is. You can simply put a debug point in <strong>TransactionAspectSupport#completeTransactionAfterThrowing()</strong> method and check which exception is thrown from where, by simply making your way back in the stacktrace.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94174bfce89b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ofbusiness-tech/hibernate-issues-series-rollbackexception-94174bfce89b">Hibernate Issues Series : RollbackException</a> was originally published in <a href="https://medium.com/ofbusiness-tech">OFB Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Yoda Search: A Slackbot for search]]></title>
            <link>https://medium.com/ofbusiness-tech/yoda-search-a-slackbot-for-search-a1c459576e3e?source=rss----8fba59e9597c---4</link>
            <guid isPermaLink="false">https://medium.com/p/a1c459576e3e</guid>
            <category><![CDATA[slackbot]]></category>
            <category><![CDATA[slack]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[bots]]></category>
            <dc:creator><![CDATA[Saraj Munjal]]></dc:creator>
            <pubDate>Tue, 30 Aug 2016 17:31:39 GMT</pubDate>
            <atom:updated>2016-08-31T15:21:46.031Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mFC4AibibxBfha9FGuWplQ.jpeg" /></figure><p>Inspired from the wisdom of our great Jedi master, we present <strong>Yoda-Search</strong>, our first contribution to OSS after being longtime fans. Incidentally, it is also a great way to kick off our tech blog :)</p><p>Essentially, Yoda is a slack bot that indexes your messages in ElasticSearch so that you can search your messages past the <strong>10,000</strong> <strong>messages </strong>limit imposed by Slack’s free tier.</p><h4>Why did we do this but?</h4><blockquote>Because, 7$ per user per month matters. — <a href="https://medium.com/u/2fe30cdece86">Vijay Rawat</a>, Jedi Knight at OFB</blockquote><p>Message search is a feature that’s part of Slack’s paid plans, starting at a minimum of 7$ per user per month. Hence, this noble thought inspired the said Jedi to use the Force and come up with a free solution to this problem.</p><h4>How can you use this?</h4><p>To execute a query privately, type:</p><blockquote>/yoda [query] , for example, /yoda deployment</blockquote><p>That queries your messages and returns matching responses from the current channel, group, or conversation. The query response is visible only to you.</p><p>For a public response, use the format:-</p><blockquote>q:[query], for example, q:hello</blockquote><p>This will do the same thing, but the query and response will be visible to everyone in your group and channel.</p><p>For detailed setup instructions, head over to our <a href="http://www.github.com/ofbusiness/yoda-search">Github repo</a>.</p><h4>Under Da Hood: For our curious brethren</h4><p>The main ingredients used here Slack’s RTM client and Elasticsearch’s JS client, wired through a simple NodeJS app which is also a simple web server.</p><p>We listen to Slack messages on channels and private groups wherever our bot is added, and direct conversations with the bot itself. All messages and files are indexed, except for the ones used to execute a search query.</p><p>A public query using the <em>q:</em> format is intercepted using the RTM client message listener, and the query string is searched in Elasticsearch across multiple message fields. The responses are posted on the same thread by our bot, visible to all members.</p><p>A private query using the <em>/yoda </em>format is a Slack <a href="https://api.slack.com/slash-commands">slash command</a>. This leads to Slack hitting our simple web server with an API call containing the search query. Again, we search our index and return responses, but this time as an HTTP response to Slack’s API call rather than an RTM message.</p><p>Initially, it was more of a fun project but after some time when enough messages were indexed into the system, we realised that this is awesome and we should share this with the world.</p><p>If you’re reading this, we strongly encourage you to raise issues and contribute to make the project better, because we have a long way to go :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1c459576e3e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ofbusiness-tech/yoda-search-a-slackbot-for-search-a1c459576e3e">Yoda Search: A Slackbot for search</a> was originally published in <a href="https://medium.com/ofbusiness-tech">OFB Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>