<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Free practice test , mock test, driving test, interview questions &#187; Spring Transactions</title>
	<atom:link href="http://www.skill-guru.com/blog/tag/spring-transactions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.skill-guru.com/blog</link>
	<description>Find free mock and practice test, create and sell tests</description>
	<lastBuildDate>Mon, 16 Jan 2012 16:53:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>@Transactional(readOnly=true) in Spring</title>
		<link>http://www.skill-guru.com/blog/2010/12/19/transactionalreadonlytrue-in-spring/</link>
		<comments>http://www.skill-guru.com/blog/2010/12/19/transactionalreadonlytrue-in-spring/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 03:26:25 +0000</pubDate>
		<dc:creator>Vinay</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[Spring Transactions]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=3017</guid>
		<description><![CDATA[@Transactional(readOnly=true) in Spring 
What does this mean ?
When a Multi Version Concurrency Control database (Oracle, Postgresql, MySQL + InnoDb) is used, a read only transaction can be translated to the non standard isolation level: READ_ONLY.
The READ_ONLY isolation level provides the same protection as the SERIALIZED isolation level (no dirty reads, no unrepeatable reads, no phantom [...]]]></description>
			<content:encoded><![CDATA[<p><strong>@Transactional(readOnly=true) in Spring </strong></p>
<p>What does this mean ?</p>
<p>When a Multi Version Concurrency Control database (Oracle, Postgresql, MySQL + InnoDb) is used, a read only transaction can be translated to the non standard isolation level: READ_ONLY.</p>
<p>The READ_ONLY isolation level provides the same protection as the SERIALIZED isolation level (no dirty reads, no unrepeatable reads, no phantom reads) but doesn&#8217;t allow any updates. It also doesn&#8217;t cause any lock contention because no locking is required (the database is able to revert back to previous versions of the records ignoring all new changes).</p>
<p>Ms Sql 2005 also has a similar isolation level: SNAPSHOT.</p>
<p>If you specify readOnly as true, the flush mode will be set as <strong>FlushMode.NEVER</strong> in the current Hibernate Session preventing the session from committing the transaction.<span id="more-3017"></span></p>
<p>Furthermore, <strong>setReadOnly(true)</strong> will be called on the JDBC Connection, which is also a hint to the underlying database. If your database supports it (most likely it does), this has basically the same effect as FlushMode.NEVER, but it&#8217;s stronger since you cannot even flush manually.</p>
<p>Now let&#8217;s see how transaction propagation works.</p>
<p>If you don&#8217;t explicitly set readOnly to true, you will have read/write transactions. Depending on the transaction attributes (like REQUIRES_NEW), sometimes your transaction is suspended at some point, a new one is started and eventually committed, and after that the first transaction is resumed.</p>
<p>If a method in a <strong>read/write</strong> transaction calls a method that requires a <strong>readOnly</strong> transaction, the first one should be suspended, because otherwise a flush/commit would happen at the end of the second method.</p>
<p>Conversely, if you call a method from within a <strong>readOnly</strong> transaction that requires <strong>read/write</strong>, again, the first one will be suspended, since it cannot be flushed/committed, and the second method needs that.</p>
<p>In the <strong>readOnly-to-readOnly</strong>, and the <strong>read/write-to-read/write</strong> cases the outer transaction doesn&#8217;t need to be suspended (unless you specify propagation otherwise, obviously).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2010/12/19/transactionalreadonlytrue-in-spring/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Spring Transaction Management &#8211; Mock Test</title>
		<link>http://www.skill-guru.com/blog/2009/09/14/spring-transaction-management-mock-test/</link>
		<comments>http://www.skill-guru.com/blog/2009/09/14/spring-transaction-management-mock-test/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 02:58:25 +0000</pubDate>
		<dc:creator>Vinay</dc:creator>
				<category><![CDATA[Mock  Exam / Certifications]]></category>
		<category><![CDATA[practice-test]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[Spring Transactions]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=637</guid>
		<description><![CDATA[A mock test on  Spring Transaction Mock test has been added to skill-guru.  This will test your understanding about Spring transaction management. Some questions are based on code samples and some are based on on Spring documentation
This test in addition to Spring technical test / Spring Interview questions
This test will also help in Spring Certification [...]]]></description>
			<content:encoded><![CDATA[<p>A mock test on <a href="http://www.skill-guru.com/skill/login/testDetails.faces?testId=36&amp;testName=Spring-Transaction-Management"> Spring Transaction Mock test </a>has been added to skill-guru.  This will test your understanding about Spring transaction management. Some questions are based on code samples and some are based on on Spring documentation</p>
<p>This test in addition to <a href="http://www.skill-guru.com/skill/login/testDetails.faces?testId=14&amp;testName=Spring-Fundamentals" target="_blank">Spring technical test</a> / <a href="http://www.skill-guru.com/skill/login/testDetails.faces?testId=14&amp;testName=Spring-Fundamentals">Spring Interview questions</a></p>
<p>This test will also help in <a href="http://www.skill-guru.com/skill/login/testDetails.faces?testId=36&amp;testName=Spring-Transaction-Management">Spring Certification exams</a></p>
<p>Update: A new test <a href="http://www.skill-guru.com/test/81/core-spring-certification-mock">Core Spring Certification Mock</a> has been added bu danielbutcher</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2009/09/14/spring-transaction-management-mock-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>User defined exception thrown in Spring Transaction</title>
		<link>http://www.skill-guru.com/blog/2009/08/17/user-defined-exception-thrown-in-spring-transaction/</link>
		<comments>http://www.skill-guru.com/blog/2009/08/17/user-defined-exception-thrown-in-spring-transaction/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 18:26:59 +0000</pubDate>
		<dc:creator>Vinay</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[Spring Transactions]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=370</guid>
		<description><![CDATA[This post is a result of a problem I faced while working on one of my project. Spring is used for managing transactions and we have not upgraded to Spring 2.5 annotation based transaction. But the concept here is important not the code
We had service class which had transaction attributes defined in applicationContext.xml file as
&#60;bean [...]]]></description>
			<content:encoded><![CDATA[<p>This post is a result of a problem I faced while working on one of my project. Spring is used for managing transactions and we have not upgraded to Spring 2.5 annotation based transaction. But the concept here is important not the code</p>
<p>We had service class which had transaction attributes defined in applicationContext.xml file as</p>
<blockquote><p>&lt;bean id=&#8221;helloService&#8221; parent=&#8221;txProxyTemplate&#8221;&gt;</p>
<p>&lt;property name=&#8221;target&#8221;&gt;<br />
&lt;bean<br />
class=&#8221;com.skillguru.impl.HelloServiceImpl&#8221;<br />
autowire=&#8221;byName&#8221; /&gt;<br />
&lt;/property&gt;</p>
<p>&lt;property name=&#8221;transactionAttributes&#8221;&gt;<br />
&lt;props&gt;<br />
&lt;prop key=&#8221;*&#8221;&gt;PROPAGATION_REQUIRED&lt;/prop&gt;<br />
&lt;/props&gt;<br />
&lt;/property&gt;<br />
&lt;/bean&gt;</p></blockquote>
<p>Within the same file,  the transaction proxy template is defined as</p>
<blockquote><p>&lt;bean id=&#8221;txProxyTemplate&#8221; abstract=&#8221;true&#8221;<br />
class=&#8221;org.springframework.transaction.interceptor.TransactionProxyFactoryBean&#8221;&gt;<br />
&lt;property name=&#8221;transactionManager&#8221;&gt;<br />
&lt;ref bean=&#8221;transactionManager&#8221; /&gt;<br />
&lt;/property&gt;<br />
&lt;property name=&#8221;transactionAttributes&#8221;&gt;<br />
&lt;props&gt;<br />
&lt;prop key=&#8221;save*&#8221;&gt;PROPAGATION_REQUIRED&lt;/prop&gt;<br />
&lt;prop key=&#8221;remove*&#8221;&gt;PROPAGATION_REQUIRED&lt;/prop&gt;<br />
&lt;prop key=&#8221;*&#8221;&gt;PROPAGATION_REQUIRED,readOnly&lt;/prop&gt;<br />
&lt;/props&gt;<br />
&lt;/property&gt;<br />
&lt;/bean&gt;</p></blockquote>
<p>The class HelloServiceImpl throws a User defined exception, UserDuplicateException</p>
<p>The logic is that a method HelloServiceImpl#saveUser inserts the user ina  aloop and then checks for duplicate user based on some coniftions.</p>
<p>If the user is duplicate , none of the records are to inserted.</p>
<p>This works fine on paper but not in real world. Reason being UserDuplicateException is  a user defined exception and not a an 			instance or subclass of <tt>RuntimeException, Spring was not rolling back the transaction.</tt></p>
<p>Look at Spring docs <a href="http://static.springsource.org/spring/docs/2.5.x/reference/transaction.html">here </a></p>
<p>For the transaction to roll back, the exception has to be configured like this</p>
<p>&lt;bean id=&#8221;helloService&#8221; parent=&#8221;txProxyTemplate&#8221;&gt;</p>
<p>&lt;property name=&#8221;target&#8221;&gt;<br />
&lt;bean</p>
<p>autowire=&#8221;byName&#8221; /&gt;<br />
&lt;/property&gt;</p>
<p>&lt;property name=&#8221;transactionAttributes&#8221;&gt;<br />
&lt;props&gt;<br />
&lt;prop key=&#8221;*&#8221;&gt;PROPAGATION_REQUIRED,-UserDuplicateException&lt;/prop&gt;<br />
&lt;/props&gt;<br />
&lt;/property&gt;<br />
&lt;/bean&gt;</p>
<p>Look at <strong>-UserDuplicateException</strong>. This is the key here. For a user defined exception to rollback , you to have define it explicitly with a -ve sign.</p>
<p>Things have changed in newer version of Spring but the concept is still same.</p>
<p>Other Spring related posts</p>
<p><a href="http://www.skill-guru.com/skill/login/testDetails.faces?testId=14">Spring Interview Questions</a></p>
<p><a href="http://www.skill-guru.com/blog/2009/07/27/which-is-better-springs-transaction-management-feature-or-ejbs-container-managed-transaction/">Which is better : Spring’s Transaction management or EJB’s Container managed transaction</a></p>
<h2><strong><br />
</strong></h2>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2009/08/17/user-defined-exception-thrown-in-spring-transaction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Which is better : Spring&#8217;s Transaction management or EJB&#8217;s Container managed transaction</title>
		<link>http://www.skill-guru.com/blog/2009/07/27/which-is-better-springs-transaction-management-feature-or-ejbs-container-managed-transaction/</link>
		<comments>http://www.skill-guru.com/blog/2009/07/27/which-is-better-springs-transaction-management-feature-or-ejbs-container-managed-transaction/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 20:58:17 +0000</pubDate>
		<dc:creator>Vinay</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[Spring Transactions]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=187</guid>
		<description><![CDATA[I was a big fan of EJB’s CMT  (Container managed transaction) feature because it reduces the developer of complex task of managing transaction through code. One of the biggest drawback of this was that this feature could only be used with EJB’s and not ordinary Java classes.
Then came the Spring’s Transaction management feature which changed [...]]]></description>
			<content:encoded><![CDATA[<p>I was a big fan of EJB’s CMT  (Container managed transaction) feature because it reduces the developer of complex task of managing transaction through code. One of the biggest drawback of this was that this feature could only be used with EJB’s and not ordinary Java classes.</p>
<p>Then came the Spring’s Transaction management feature which changed the way applications can manage transactions.  We will explore about Spring’s transactional capabilities and if they are better than EJB’s transaction</p>
<p><span id="more-187"></span></p>
<p>Spring provides two types of transaction</p>
<p>a)  Programmatic Transaction : This is used when developer would like to write the transaction related code himself</p>
<p>b) Declarative transaction :  This is enabled by Spring AOP and as the transactional aspects code comes with Spring and may be used in a boilerplate fashion</p>
<p><strong> </strong></p>
<p>Most developers prefer <strong>declarative transaction</strong> as it has least impact on application code<strong> </strong></p>
<p><strong>Feature of Spring Transaction</strong> :</p>
<ul>
<li>Spring Framework&#8217;s declarative transaction management is not tied to JTA therefore works in any environment. It can work with JDBC, JDO, Hibernate or other transactions under the covers, with configuration changes only.</li>
</ul>
<blockquote><p>For eg in this class below</p>
<p>}</p>
<p>public class RecordHibernateDAO implements RecordsDAO {</p>
<p>public void addRecords(Records record ){</p>
<p>//do something</p>
<p>}</p></blockquote>
<p>We can mange the transaction by adding this annotation for the method addrecords</p>
<blockquote><p><strong>@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)</strong></p>
<p>}</p>
<p>public void addRecords(Records record ){</p>
<p>//do something</p></blockquote>
<ul>
<li>The Spring Framework enables declarative transaction management to be applied to any class, not merely special classes such as EJBs. For eg in the above example instead of HibernateDAO class we could have a plain java class on which transaction capabilities can be applied. This makes life so much easy for an application developer. Now he is not constrained by “business logic” residing inside EJB only.</li>
</ul>
<ul>
<li>The Spring Framework offers declarative rollback rules: this is a feature with no EJB equivalent. Both programmatic and declarative support for rollback rules is provided. This especially comes handy when you want transaction to be rolled back for certain exceptions only.</li>
</ul>
<ul>
<li>The Spring Framework gives you an opportunity to customize transactional behavior, using AOP. For example, if you want to insert custom behavior in the case of transaction rollback, you can. You can also add arbitrary advice, along with the transactional advice. With EJB CMT, you have no way to influence the container&#8217;s transaction management other than setRollbackOnly().</li>
</ul>
<ul>
<li>The Spring Framework does not support propagation of transaction contexts across remote calls, as do high-end application servers. EJB is much better suited for this.</li>
</ul>
<p>After having said all this , you can clearly decide which one is better. I went with Spring transactions because it gives me the ability to manage transaction decoratively with out having to bear the additional overhead of an Application server</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2009/07/27/which-is-better-springs-transaction-management-feature-or-ejbs-container-managed-transaction/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

