Difference between local and global transaction ?



Difference between local and global transaction ?..

Answer / prakash sah

Here is the defination and example in case of spring:

Local Vs Global Transaction:

Local transactions are transactions associated with a
particalar data source (means they are resource-specific).
the most common example would be a transaction associated
with a JDBC connection. While Global Transactions provide
the ability to work with multiple transactional resources
(typically relational databases and message queues).

Example of Local transaction :

<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>

<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>

DataSourceTransactionManager : takes the datasource as one
of its properties.

even HibarnateTransactionManager takes sessionfactory which
in turn uses datasource as a property or it also takes
datasource as one of the property.


Example of Global transaction :

If we use JTA in a J2EE container, as in the
'dataAccessContext-jta.xml' file from the same sample
application, we use a container DataSource, obtained via
JNDI, in conjunction with Spring's
JtaTransactionManager. The JtaTransactionManager doesn't
need to know about the DataSource, or any
other specific resources, as it will use the container's
global transaction management infrastructure.


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/jpetstore"/>
<bean id="txManager"
class="org.springframework.transaction.jta.JtaTransactionManager"
/>
<!-- other <bean/> definitions here -->
</beans>

Is This Answer Correct ?    10 Yes 3 No

Post New Answer

More Core Java Interview Questions

Explain Basics of OOP Language in java

0 Answers   Atos Origin,


Why do we need autoboxing in java?

0 Answers  


Hi friends i want display Triangle shap stars(*) please can tell me any one java code logic? * *** ***** ******* Like this

2 Answers   NIIT, TCS,


What is the purpose of declaring a variable as final?

0 Answers  


What are exceptions

0 Answers   Futures First,






What is function and method in java?

0 Answers  


What is a java developer salary?

0 Answers  


What is the functionability stubs and skeletons?

0 Answers  


Can we have try block without catch block?

0 Answers  


How to create an interface?

0 Answers  


How to sort an unsorted array in java?

0 Answers  


What is static import in java?

0 Answers  


Categories