Announcement Announcement Module
Collapse
No announcement yet.
Disable Transactions for Hibernate calling Stored Procedures Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Disable Transactions for Hibernate calling Stored Procedures

    Hi All,

    For our web application, all DB access is performed via stored procedures. This design decision is set in stone and there is no way I can change it.

    Additionally, all transaction handling is done within the stored procedures. The Java layer must not use transactions.

    I can easily accomplish this using plain JDBC. But Id prefer to use Hibernate for its ORM and caching features.

    Calling stored procedures with Hibernate is easy:

    Code:
    final Session session = sessionFactory.getCurrentSession();
    final Query query = session.createSQLQuery("EXEC dbo.SP_ProductSearch :searchStr").addEntity(Product.class).setString("searchStr", "ap");
    return query.list();
    But when I run a DB profile, I see the following.

    Code:
    SET IMPLICIT_TRANSACTIONS ON
    EXEC dbo.SP_ProductSearch  N'ap'
    IF @@TRANCOUNT > 0 COMMIT TRAN
    IF @@TRANCOUNT > 0 COMMIT TRAN
    SET IMPLICIT_TRANSACTIONS OFF
    Is there anyway I can disable the 4x transaction statements?

    My technology stack is as follows.

    Spring 3.1.2
    Hibernate 4.1.8
    jTDS (JDBC driver) 1.2.5
    MS SQL Server 10.x

    Many thanks in advance... Adam.

  • #2
    I haven't discovered any way to prevent Hibernate from using transactions, so as a work-around I've switched to MyBatis which works perfectly.

    http://www.mybatis.org/spring/index.html

    Comment

    Working...
    X