-->
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.  [ 4 posts ] 
Author Message
 Post subject: db socket exception (w/Spring and Tomcat)
PostPosted: Thu Feb 12, 2004 1:31 am 
Regular
Regular

Joined: Mon Nov 03, 2003 6:10 am
Posts: 75
Occassionally I get the following error; sometimes on the first execute! From that point on the only thing I can do is reboot Tomcat. I search the forum and noticed some references to C3PO etc. I have included my config below.. as well as the error.

Appreciate any insight!


net.sf.hibernate.JDBCException: Could not execute query
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1454)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:43)
at com.temp.data.OrderManager.getOrder(OrderManager.java:60)
...
caused by:
Caused by: java.sql.SQLException: Io exception: Socket closed at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333) at oracle.jdbc.driver.OracleConnection.setAutoCommit(OracleConnection.java:1224) at org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:237) at net.sf.hibernate.transaction.JDBCTransaction.begin


<bean id="hibernateOracleSessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="oracleDataSource"/>
</property>
<property name="mappingResources">
<list>
<value>com/test/data/Order.hbm.xml</value>
...
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.jdbc.batch_size">25</prop>
<prop key="hibernate.use_outer_join">true</prop>
<prop key="hibernate.connection.pool_size">20</prop>
<!-- TODO: will provider class and factory class work?? -->
<prop key="hibernate.connection.provider_class">net.sf.hibernate.connection.C3P0ConnectionProvider</prop>
<prop key="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</prop>
<!-- TODO: org.spring.orm.hibernate.HibernateTransactionManager can this be used here? -->
<!-- net.sf.hibernate.transaction.JTATransactionFactory -->

<prop key="hibernate.c3p0.max_size">25</prop>
<prop key="hibernate.c3p0.min_size">2</prop>
<prop key="hibernate.c3p0.timeout">5000</prop>
<!-- <prop key="hibernate.c3p0.max_statements">250</property> -->
<prop key="hibernate.c3p0.validate">false</prop>
</props>
</property>
</bean>


Top
 Profile  
 
 Post subject: more info
PostPosted: Thu Feb 12, 2004 2:03 am 
Regular
Regular

Joined: Mon Nov 03, 2003 6:10 am
Posts: 75
I noticed that even tho I close my connections after each use, I still see warnings in my log. Below is a sample log and the code I am using to close my connections.

21:44:48,599 INFO [http8100-Processor3] com.test.data.OrderManager:49 - Start of OrderManager.getOrder()
21:44:48,709 INFO [http8100-Processor3] com.test.data.OrderManager:65 - End of OrderManager.getOrder
21:44:48,709 INFO [http8100-Processor3] com.test.data.HibernateUtil:127 - Start of HibernateUtil.scrub()
21:44:48,719 INFO [http8100-Processor3] com.test.data.HibernateUtil:138 - End of HibernateUtil.scrub
21:44:49,450 WARN [Finalizer] net.sf.hibernate.impl.SessionImpl:3347 - unclosed connection
21:44:49,450 WARN [Finalizer] net.sf.hibernate.impl.SessionImpl:3347 - unclosed connection


public void scrub(Session session) {
logger.info("Start of HibernateUtil.scrub()");
if(null != session && session.isOpen()) {
try {
// session.flush();
session.close();
} catch(HibernateException e) {
/* Eat error... for simplicity */
e.printStackTrace();
}
// session = null; // will this help speed up clean up?
}
logger.info("End of HibernateUtil.scrub");
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 4:43 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Are you sure:
Code:
null != session && session.isOpen()

is being evaluated to true and session.close() is being executed. Put some logging here.

Where is your tx start() and commit()? What context (J2EE server, standalone...) are you invoking this in?

Also - your session.close() should be in a finally block otherwise if an exception is encountered, the session will not be closed.

The 'pattern' is (from the manual):
Code:
Session sess = factory.openSession();
Transaction tx = null;
try {
  tx = sess.beginTransaction();
  // do some work
  tx.commit();
}
catch (Exception e) {
  if (tx!=null) tx.rollback();
  throw e;
}
finally {
  sess.close();
}


Top
 Profile  
 
 Post subject: got it
PostPosted: Thu Feb 12, 2004 4:52 am 
Regular
Regular

Joined: Mon Nov 03, 2003 6:10 am
Posts: 75
I did some clean up and found 2 cases where I was using:

session.createQuery(sql);

I ensured that they call HibernateUtil.scrub(session) and all is well now.

I was in the process of making a single point of entry for the hibernate stuff so that this wouldn't be a problem.. and I left a hole!

Now my logs are clean and all is well.

Except for the following warning:

afterTransactionCompletion() was never called

I couldn't find anything on this beyond the javadoc.

Should I be concerned? Is there a best practice that I should implement that I haven't?


Thanks

Troy

p.s. Hibernate Rocks!
I just finished a POC for a client of mine and we will be using it along with Websphere Portal for their application. Trying to sneak Spring in there as well... but not too sure on how to work that with Portal .. oh well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.