How to log start and end of DB transactions in Hibernate
sql_show = true
this property in hibernate prints executable sql, but I want to see the statements begin transaction
and complete transaction
so that I can track the duration of the transaction and see the execution of the query in the transaction.
googling shows that
log4j.logger.org.hibernate.SQL = DEBUG, defaultAppender
log4j.logger.org.hibernate.type = DEBUG, defaultAppender
log4j.logger.org.hibernate.transaction=DEBUG, defaultAppender
should also show transaction level data. But this is not the case.
Investigating more, I looked through the hibernate code and found the class name
org.hibernate.ejb.TransactionImpl
this class has begin and complete method, but this method does not write anything.
Any advice on how to view transaction level information while sleeping ?
I am using hibernate 2.2
source to share
You need to set the registration threshold for DEBUG for the following classes:
-
For JDBC transactions (like RESOURCE_LOCAL)
-
For logging SLF4J:
<logger name="org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction" level="debug"/>
-
For Log4j:
<logger name="org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction"> <level value="DEBUG"/> </logger>
-
-
For JTA transactions
-
For logging SLF4J:
<logger name="org.hibernate.engine.transaction.internal.jta.JtaTransaction" level="debug"/>
-
For Log4j:
<logger name="org.hibernate.engine.transaction.internal.jta.JtaTransaction"> <level value="DEBUG"/> </logger>
-
You will see the following entries in the logs:
-
when the transaction starts:
DEBUG [Alice]: o.h.e.t.i.j.JdbcTransaction - initial autocommit status: true DEBUG [Alice]: o.h.e.t.i.j.JdbcTransaction - disabling autocommit
-
when the transaction ends:
DEBUG [Alice]: o.h.e.t.i.j.JdbcTransaction - committed JDBC Connection DEBUG [Alice]: o.h.e.t.i.j.JdbcTransaction - re-enabling autocommit
It is best to activate the DEBUG level for as many classes as possible, otherwise the size of your logs will increase dramatically.
source to share