简体   繁体   中英

JDBC, Hibernate and Implicit Transactions on SQL Server 2008

We're having some problems with connections getting 'stuck' on SQL Server 2008 when issued from Hibernate, running on a Glassfish instance.

Occasionally, there will be 10 or 20 calls to a stored procedure, that are all 'sleeping' , and are holding open a number of transactions.

When i use DBCC INPUTBUFFER to find out more about them, it has:

Name : implicit_transaction

Does this mean that the java app, is setting 'SET IMPLICIT_TRANSACTIONS ON' as part of the batch? The only way I was able to replciate that transaction name DB side, was to use that syntax.

It appears that the java app is hanging on to the connection, but somehow losing context of the call itself, as such it never comes back to commit the transaction.

The java developers say that they are not explicitly defining any connections, and are not away that they are setting any other connection properties on purpose. The calls are all being made under the READ COMMITTED isolation level.

How can I found out whether there's some hidden attribute set, or if some hibernate setting is causing this annoying behaviour?

You can ask Hibernate to log the sql statements it's executing.

This article describes two ways to do that.

SessionFactory sf = new Configuration()
    .setProperty("hibernate.show_sql", "true")
    // ...
    .buildSessionFactory();

or in the log4j configuration

log4j.logger.org.hibernate.SQL=DEBUG, SQL_APPENDER
log4j.additivity.org.hibernate.SQL=false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM