Hibernate session.beginTransaction() call and Mysq

2019-05-21 07:07发布

问题:

When I issue the command

session.beginTransaction();
// do something
session.getTransaction().commit();

I don't see a corresponding Start Transaction command issue to my database. Can any body explain to why it is not there and how mysql knows the boundary of a transaction.

Thanks,

回答1:

As briefly mentioned in the Hibernate Developer Guide, JDBC does not define an explicit method for beginning a transaction. The Java JDBC Tutorial mentions disabling auto-commit mode to be able to group two or more statements into a transaction. This is exactly what Hibernate does in the session.beginTransaction() call.