-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Transaction, pooling and jTDS
PostPosted: Mon Aug 09, 2004 5:20 am 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
FYI.

I came across an odd problem with the jTDS driver combined with the connection pooling ( DBCP or C3P0 ). jTDS uses a caching system which creates a temporary stored procedure for every unique query string and then re-executes the proc when the same query is rerun.

However this didn't seem to be working for me despite running exactly the same query. After some digging through the combined hibernate, connection pool and jTDS code I discovered that the following happened.

Code:
session.close()

calls:

connectionPool.releaseConnection()

calls:

jTDSConnection.rollback()


which deletes any stored procedures created in the current transaction.

And all because I was doing this everywhere:

Code:
Session session = factory.openSession()
session.find( query );
session.close();


and not using a transaction like this.

Code:
Session session = factory.openSession()
Transaction tx = session.beginTransaction();
session.find( query );
tx.commit();
session.close();


Because the session.find() will always open a transaction implicitly when the connection is released the pool will ensure it doesn't have a transaction still open by calling rollback() on it to cleanup. So using an explicit transaction and calling commit() will properly close the current transaction so the driver doesn't delete the stored procs.

Yet another reason to always use a transaction explicitly even when just using a find().

This was with SQLServer 2000, jTDS driver, DBCP or C3P0 pool and hibernate 2.1.1 but it may be relevant to other drivers/dbs/pools.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 4:36 pm 
Regular
Regular

Joined: Mon Sep 29, 2003 9:39 am
Posts: 67
thanks for posting this useful tip.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.