-->
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.  [ 5 posts ] 
Author Message
 Post subject: Direct sql query from connection causes "Thread Death&q
PostPosted: Wed Jan 28, 2004 3:56 am 
Hi all,

We are running hibernate 2.0 in Jboss as a SAR. We would be much obliged for any help fixing the problem in our code that results in "thread death".

In the part of our code that builds generic read only tabular reports , we are executing direct sql instead of object / relational persistence (please see below)

Sometimes, this code works fine, but other times "thread death" occurs (this is indicated to us in the eclipse IDE, from the debug perspective, by the way). When we put a trace on the database, the query never reaches the database in these cases.

Our application is architected as follows: jsp pages triggers struts action, struts action calls stateless ejb, stateless ejb calls a helper class' static method with the code snipped below. So we are relying on struts and ejb to do all the the threading workl

I have given two examples of sqlStrings that could be executed. Interesting, the first version with a compound ORDER By clause is much more likely then the second version with a simple order by clause to cause thread death.


Thanks in Advance,

Eliotc sleepless in San Diego!





(Version 1) String sqlString = "SELECT distinct metricId,
metricFullDescription,
auditSubjectDescription,
auditCategoryDescription
FROM dbo.vw_appl_company_metric_type vw
WHERE vw.companyId = '4741N'
AND vw.calendar_quarter_number = 176
ORDER BY auditSubjectDescription, metricFullDescription";


(Version 2) String sqlString = "SELECT distinct metricId,
metricFullDescription,
auditSubjectDescription,
auditCategoryDescription
FROM dbo.vw_appl_company_metric_type vw
WHERE vw.companyId = '4741N'
AND vw.calendar_quarter_number = 176
ORDER BY metricFullDescription";
.....

// ================================
// Declare method variables
// ================================
List queryResultRows = new ArrayList();
Session aSession = null;
Connection aConnection = null;
Statement aSqlStatement = null;
ResultSet aResultSet = null;

// ================================
// Get connection, and execute the sql query
// ================================
try // needed for finally block
{
try
{
aSession = JndiFactory.getHibernateSession();
aConnection = aSession.connection();
aSqlStatement = aConnection.createStatement();



}
catch (Exception e)
{
throw new DatabaseNotAvailableException("Could not obtain handle to Hibernate session or connection", e);
}


try
{
Log.debugInfo(TabularReportFactory.class, METHOD, new String[] {"About to run statement: ", sqlString });
aResultSet = aSqlStatement.executeQuery(sqlString); //@@@THREAD death occurs at the executeQuery() call

Log.debugInfo(TabularReportFactory.class, METHOD, new String[] {"Completed running statement" });
} catch (SQLException e)
{
throw new AuditManagerException("Could not execute sql statement", e);
}


Top
  
 
 Post subject:
PostPosted: Wed Jan 28, 2004 4:20 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
You need to provide some more info, including:

Database type and version
Driver type and version
Application Server version

Please enable debugging and also include a debug trace.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 28, 2004 7:32 pm 
Hi,

Relevant details:
Database = Sql SErver 2000, developer edition
Driver = TwFreeTds_1.3.jar
Application server = Jboss 3.2.1
Hibernate 2.0.x deplyed as a SAR

Since this morning, based on your hint the driver might be the problem, I have developed a workaround as follows:

(1) I no longer close the connection, but only the ResultSet, statement and Hibernate session. Hibernate seems to have a slight bug, whereby closing connections in the hibernate connection pool really closes them, instead of just returning them to the pool for reuse! This didn't eliminate thread death, but it did slow down the rate at which the JVM suffocated.

Code snippet after change (1):

} finally
{
try
{
aResultSet.close();
aSqlStatement.close();
//aConnection.close(); Commented out 'cause problem.
aSession.close();
} catch (Exception e)
{ /* silent */ }
} //end finally




(2) More importantly I have changed to the driver jtds-0.6.jar. In addition to eliminating thread death it is a massively quicker driver and also true open source.

Thanks for ideas, Eliot


drj wrote:
You need to provide some more info, including:

Database type and version
Driver type and version
Application Server version

Please enable debugging and also include a debug trace.


Top
  
 
 Post subject:
PostPosted: Thu Jan 29, 2004 1:11 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Great.
As far as I know- when you get a connection using session.connection() you shouldn't call close on it. I had a similar problem occuring using tomcat and apache dbcp in that if I called close(), the next operation failed with an error like "Connection is closed"

I can't find any info in the docs (API/Reference) on this (whether you are responsible for closing the connection or not). Perhaps someone can enlighten me....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2004 7:23 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hibernate is still responsible of the connection, so don't close it.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.