Dilip Ganesh
Dilip Ganesh

Reputation: 101

Need of Transaction API in Java

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

Answers (2)

Adi Sembiring
Adi Sembiring

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

HJW
HJW

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

Related Questions