First of all my question is What is the need of Transaction API in java ? Give me the practical example?
What is the meaning for Container Managed Transaction and Bean Managed Transaction?
And Difference between Declarative Transaction and Programmatic Transaction?
Please help me
Thanks in advance
Declarative transaction: you put the transaction declarative in the method declaration. so you doesn't need to implement the transaction manually. Here I give you the example:
// declarative
@Transcational
public void Transfer (Account from, Account destination, double amount) {
//do your logic here
}
// programmatic
public void Transfer (Account from, Account destination, double amount) {
var session = sessionFactory.openSession();
var tx = session.BeginTransaction();
try {
//do you logic here
tx.Commit();
} catch {
tx.Rolback();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With