Does hibernate use jdbc or JTA internally, or is it customizable? "

I am new to sleep mode and started to learn sleep mode. The chapter I'm going to use sleep mode with JDBC (). Does hibernate use internal jdbc or JTA to perform persistence and perform operations? But I also see the JTA mentioned here, similar to the getCurrentSeessionSession () method, which receives the session associated with the current JTA transaction. Question: - Basically, I want to understand the role of JTA and jdbc here in sleep mode.

Question2: - I see below a code fragment in any operation in sleep mode

try{ session=factory.openSession(); tx=session.beginTransaction(); session.save(myClass); tx.commit(); } finally{ session.close(); } 

Here I want to understand the role of the string // tx = session.beginTransaction (); In accordance with the understanding, each session will use one connection. So even if we start several transactions from the same session, we will use the same connection. after we complete a transaction for each transaction created from the same session, it will be executed once. So what are we trying to achieve with // tx = session.beginTransaction ();

+5
hibernate
source share
1 answer

Does hibernate use jdbc internally or JTA internally to save and retrieve operations?

JDBC and JTA are not interchangeable. JDBC is the standard API that Java applications use to interact with the database. JTA is a standard API for managing transactions through one or more resources. The closest answer to your question would be that “internally”, Hibernate uses JDBC to interact with the database.

How the getCurrentSeessionSession () method gets the session associated with the current JTA transaction.

Not really. SessionFactory.getCurrentSession () gets the session according to the current session context . One implementation of this strategy is the context of a JTA session , which essentially associates sessions with a JTA transaction. There is no Hibernate session in the JTA transaction, since the JTA does not know anything about Hibernate, and it would be wrong to say that Hibernate uses JTA internally. It just has the ability to integrate with JTA and allows you to manage transactions.

here I want to understand the role of the line // tx = session.beginTransaction ();

It starts a transaction in any used transaction mechanism that is controlled by a TransactionFactory . For example, using JDBCTransactionFactory, it simply ensures that auto-commit is disabled so that changes are not committed until the transaction completes.

after we commit a specific transaction, all transactions created from one session will be completed once.

Under normal circumstances, a session is associated with only one transaction. Several calls to Session.beginTransaction () simply return the same Transaction .

So what are we trying to achieve with // tx = session.beginTransaction ()

Just this: let us know that it controls your transactions, that you are starting a new transaction. This means that everything that happens until you execute commit () or rollback () must have generally accepted database transaction semantics .

+12
source share

All Articles