이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 5. Managing JTA transactions programmatically using the API approach
You can manage transaction boundaries programmatically by injecting UserTransaction. The following chapters demonstrate how you can manage JTA transactions and define transaction boundaries using the API approach.
5.1. Defining transaction boundaries using the API approach 링크 복사링크가 클립보드에 복사되었습니다!
You can inject a UserTransaction and manage the transaction boundaries by calling its begin(), commit() and rollback() methods.
Procedure
Inject the
UserTransactioninterface:src/main/java/org/acme/SantaClauseService.java
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the transaction demarcation methods to control the transaction:
src/main/java/org/acme/SantaClauseService.java
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteYou cannot use
UserTransactionin a method where a transaction starts by a@Transactionalcall.
5.2. Configuring a transaction for rollback using the API approach 링크 복사링크가 클립보드에 복사되었습니다!
Exceptions caused by system-level faults mark the transactions for rollback. You can mark the transaction for rollback programmatically by injecting TransactionManager.
Procedure
Inject the
TransactionManagerand set the transaction for rollback withsetRollbackOnly:In this example, the transaction context is propagated to all calls nested in the
@Transactionalmethod (childDAO.addToGiftList()andsantaDAO.addToSantaTodoList()). The transaction manager commits the transaction unless a runtime exception crosses the method boundary.Example src/main/java/org/acme/SantaClausService.java
Copy to Clipboard Copied! Toggle word wrap Toggle overflow