Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between a hibernate transaction and a database transaction done using sql queries?

Is there a difference between the two? For example within a hibernate transaction we can access the database, run some java code and then access the database again. We can't do that within a transaction done via SQL can we? Is this the difference?

like image 908
Can't Tell Avatar asked Jan 01 '12 04:01

Can't Tell


People also ask

What is the difference between transaction and query?

Here a simple explanation: Queries are operations to CRUD (create (insert), update (set), read (select), delete (delete)) data inside a table. The transaction is more or less the process of a single or multiple statements/queries/operations getting executed.

What is the difference between spring transaction and hibernate transaction?

Spring framework is useful for transaction management, dependency injection; aspect-oriented programming for applications whereas Hibernate framework is useful for object-relational persistence, access data layers, and query retrieval services for enterprise-level applications.

What is a Hibernate transaction?

Transaction Interface in Hibernate In hibernate framework, we have Transaction interface that defines the unit of work. It maintains abstraction from the transaction implementation (JTA,JDBC). A transaction is associated with Session and instantiated by calling session. beginTransaction().

What is transaction in SQL database?

A transaction is a single unit of work. If a transaction is successful, all of the data modifications made during the transaction are committed and become a permanent part of the database. If a transaction encounters errors and must be canceled or rolled back, then all of the data modifications are erased.


1 Answers

The 2 directly relate to each other - a Hibernate transaction maps to and controls the JDBC (database) transaction.

You can do the same thing with direct JDBC / SQL, without Hibernate - though you'll need to call Connection.setAutoCommit(false) to get started. Otherwise, by default, a commit is called after each statement - making each statement run in its own transaction.

Some additional details are available at http://docs.oracle.com/javase/tutorial/jdbc/basics/transactions.html.

like image 58
ziesemer Avatar answered Sep 21 '22 15:09

ziesemer