1
|
I am new to hibernate and started studying hibernate.The chapter i am going thru uses hibernate with JDBC().My first question is Does hibernate use jdbc internally or JTA internally to perform persist and get operations? But I can see some mention of JTA also here, like getCurrentSeessionSession() method obtains the session associated with current JTA transaction. Question:- Basically I want to understand the role of JTA and jdbc here in hibernate.
Question2 :- I can see below code snippet in any operation in hibernate
here, I want to understand the role of line // tx=session.beginTransaction(); As per understanding, each session will be using one connection . So even if we start multiple transactions from the same session, we will be using same connection. once we commit the specific transaction all transactions created from the same session will be committed once. So what are we trying to achieve with // tx=session.beginTransaction(); ?
| |||
add comment |
3
|
JDBC and JTA aren't interchangeable. JDBC is the standard API that Java applications use to interact with a database. JTA is the standard API for managing transactions across one or more resources. The closest answer to your question would be that "internally", Hibernate uses JDBC to interact with the database.
Not exactly. SessionFactory.getCurrentSession() gets a session according to the current session context. One implementation of that strategy is the JTA session context, which essentially associates sessions with a JTA transaction. A JTA transaction doesn't "have" a Hibernate session, since JTA knows nothing about Hibernate, and it wouldn't be quite right to say that Hibernate uses JTA internally. It simply has the ability to integrate with JTA and let it manage transactions.
It begins a transaction in whatever transaction mechanism you're using, which is governed by theTransactionFactory in use. For instance, with the JDBCTransactionFactory, it just ensures auto-commitis turned off so that changes won't be committed until the transaction is complete.
Under normal circumstances, a Session is associated to only one transaction. Multiple calls to Session.beginTransaction() will simply return the same underlying Transaction.
Just that: tell whatever is managing your transactions that you're beginning a new transaction. That implies that everything that happens until you commit() or rollback() should have the generally accepted semantics of a database transaction.
| ||||||||||||
|