Provides a consistent abstraction for transaction management. This abstraction is one of the most important of Spring’s abstractions wethout transaction data definition language operation is not perform, and delivers the following benefits:
1 Provides a consistent programming model across different ORM Database Layer and JDO.
2 Provides a simpler, easier to use, API for programmatic transaction transaction APIs
3 Integrates with the Spring data access abstraction
4 Supports Spring declarative transaction management
Transaction strategies
The key to the Spring transaction abstraction is the notion of a transaction strategy.
This is in org.springframework.transaction.PlatformTransactionManager interface Methods are available in transaction are
1 beginTransaction().
2 commitTransaction().
3 rolleBack().
4 setTimeout().
And these methods show TransactionException
every transaction follows ACID property
1 A atomicity.
2 C compatibility.
3 I isolation.
4 D dueribility.
We are using hibernate supported transaction management we put following code in beans in spring
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <bean id="txManager" class="org.springframework.orm.hibernate.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <pre> <pre brush="java"> Or <bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager"/> These beans are declarative transaction management in the spring configuration file. Plateform based declarative transaction <bean id="test"> ... </bean> <bean id="test" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager" ref="txManager"/> <property name="target" ref="test"/> <property name="transactionAttributes"> <props> <prop key="insert*">PROPAGATION_REQUIRED,-MyCheckedException</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean> |
The default transactions strategies are apply are as follows:
• Exception Handling: RuntimeExceptions roll-back, normal (checked) Exceptions don’t
• Transactions are read/write
• Isolation Level: TransactionDefinition.ISOLATION_DEFAULT
• Timeout: TransactionDefinition.TIMEOUT_DEFAULT