Difference between a hibernate transaction and a database transaction

来源:互联网 发布:虚航软件 编辑:程序博客网 时间:2024/05/18 20:08

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?

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.

0 0