Reputation: 101
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
Upvotes: 3
Views: 231
Reputation: 5946
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();
}
}
Upvotes: 1
Reputation: 23453
Container managed transaction
and bean managed transaction
, i guess you are referring to Enterprise JavaBean
? From my understanding, container managed transaction will not require the developer to explicitly write codes or constructs to manage the transaction, analogous to auto-commits for database.
Upvotes: 0