-->
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: Connection returned from Session.connection() closes.
PostPosted: Fri Oct 10, 2003 9:41 am 
Beginner
Beginner

Joined: Fri Sep 05, 2003 10:17 am
Posts: 42
I was under the impression that a JDBC connection that is returned from the connection method on the Session oject is a standalone JDBC connection.

For example:
Code:
try{
   Connection c  = HibernateSession.currentSession().connection();
   // do the work with a prepared stmnt.
   // get a resultset
   // set the data in the resultset to a local variabe and return it to the client
}catch( Exception ) { // do something
}finally{
   // close the connection
}


as compared to:
Code:
Context initContext = new InitialContext();
    DataSource ds = (DataSource) initContext.lookup (Constants.JNDI_JDBC_KEY);
con = ds.getConnection();
// do the same work as above
// close everything the same way


Here is the problem when i use straight JDBC i can get the data and all is well as i would expect but when i use the connection returned from the Session it gets the data from the DB (i can see this from debug output at the bottom of the method) but as soon as the mehod returns, i get the exception:
Quote:
java.sql.SQLException: Connection is closed.


why is this? i set the results to a local var then return it to the caller. the implementation is exact except where i get the JDBC connection from.

Please folks what is happening here?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 10, 2003 10:17 am 
Beginner
Beginner

Joined: Fri Sep 05, 2003 10:17 am
Posts: 42
I figured it out... It appears that the JDBC connection is the undlying connection for the Session and as such you cannot treat is as disconnected from the Session.

This actually makes sense on review but is a little confusing from the documentation. Then again, perhaps it is I that am confusing.


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.