28-Transactions Flashcards
Propagations in Transactional
- MANDATORY: throw an exception if no current txn
- NESTED: create nested transaction if current txn exists, create new txn otherwise
- NEVER: throws an exception if current txn exists
- NOT_SUPPORTED: run without txn
- REQUIRED: create new txn if not exist
- REQUIRES_NEW: create new txn if not exist. Run in new independent txn otherwise
- SUPPORTS: don’t create txn. Just use if exists
Difference between Propagation.REQUIRED_NEW and Propagation.NESTED
REQUIRED_NEW: suspend current transaction, create a new transaction which won’t affect outer transaction if fails
NESTED: create a nested transaction if the current transaction exists. Failure in the nested transaction will roll back the current one.
Isolations in Transactional
DEFAULT READ_UNCOMMITTED READ_COMMITTED REPEATABLE_READ SERIALIZABLE
___means that none of the actions taken in a transaction violate any integrity constraints (e.g. foreign key constraint)
C in ACID
Transaction APIs supported by Spring
JTA: java transaction API - distributed transaction
Hibernate
JPA
JDO
What is D in ACID?
Committed changes are permanent
Create JDBC transaction
conn = dataSource.getConnection()
conn. setAutoCommit(false)
conn. commit()
conn. rollback()
Create JMS transaction
session = conn.createSession(true, 0)
session. commit()
session. rollback()
Create JPA transaction
tx = entityManager.getTransaction()
tx. begin()
tx. commit()
tx. rollback()
Create Hibernate transaction
tx = session.beginTransaction()
tx. commit()
tx. rollback()
What is the difference between local and global transactions?
Local: single resource (e.g. db) & connection
Global: multiple resources (distributed transaction)
What is the requirement for using JTA?
JTA implementation e.g.
- Full application server (WebSphere, JBoss, WebLogic)
- Standalone implementation (Atomikos, JTOM)
What API does Spring use for the global and local transactions?
Use the same API
What is the base interface that Spring uses to abstract transaction APIs?
PlatformTransactionManager
Annotation to enable transaction in Spring. Where we should put it?
@EnableTransactionManager
Add it to a configuration class
List down 6 implementations of PlatformTransactionManager?
- DataSourceTransactionManager
- JmsTransactionManager
- JpaTransactionManager
- JtaTransactionManager
- WebLogicJtaTransactionManager
- WebSphereUowTransactionManager
Recommended bean name for transaction management bean?
transactionManager