Giriş
Eski kodlarda şu satırı dahil ederiz.
import javax.transaction.UserTransaction;
Şu satırı dahil ederiz
import jakarta.transaction.UserTransaction;
UserTransaction interface: This provides the application with the ability to control transaction boundaries programmatically.
Maven
API için şu satırı dahil deriz
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
<version>1.3</version>
</dependency>
Örnek
@Resource
UserTransaction utx;
public void transferFunds(Account debitAccount, Account creditAccount, double amount)
throws Exception {
try {
utx.begin();
debitAccount.withdraw(amount);
creditAccount.deposit(amount);
utx.commit();
catch (Exception e) {
utx.rollback();
throw e;
}
}