Announcement Announcement Module
No announcement yet.
Ongoing issues with c3po hibernate and sql server Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ongoing issues with c3po hibernate and sql server

    I've set up spring to do the transaction handling in the standard way:
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource" ref="dataSource"/>


    Then in my service classes I have:
    @Transactional(readOnly = true)

    All my methods are readonly transactions only reading from the database at this stage.
    I then set up my datasource as so:
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="${jdbc.driverClassName}"/>
    <property name="jdbcUrl" value="${jdbc.url}"/>
    <property name="user" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
    <property name="idleConnectionTestPeriod" value="10800"/>
    <property name="maxIdleTime" value="21600"/>
    <property name="maxStatements" value="0"/>
    The url and username/password connect fine and the application runs for roughly two days with no problem. Then all of a sudden I get the following error:
    [twl-play] WARN [Timer-0] | com.mchange.v2.async.ThreadPoolAsynchronousRunner$ [email protected] -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
    [twl-play] WARN [Timer-0] | com.mchange.v2.async.ThreadPoolAsynchronousRunner$ [email protected] -- APPARENT DEADLOCK!!! Complete Status:

    And sql server kicks out my user I'm connecting with and application can no longer hit the database.
    I've tried using DBCP and ran into countless problems. Where suddenly I can't connect to the database:

    Caused by: java.sql.SQLException: Network error IOException: Connection refused: connect
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(C
    at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(C
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.ja va:182)
    at eateConnection(
    at org.apache.commons.dbcp.PoolableConnectionFactory. makeObject(
    at org.apache.commons.pool.impl.GenericObjectPool.bor rowObject(
    at org.apache.commons.dbcp.PoolingDataSource.getConne ction(
    at org.apache.commons.dbcp.BasicDataSource.getConnect ion(
    at org.springframework.jdbc.datasource.DataSourceTran sactionManager.doBegin(DataSourceTransactionManage
    ... 39 more
    Caused by: Connection refused: connect
    at Method)
    at .java:333)
    at ava:182)
    at ava:366)
    at sun.reflect.GeneratedMethodAccessor65.invoke(Unkno wn Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De
    at java.lang.reflect.Method.invoke(
    at net.sourceforge.jtds.jdbc.SharedSocket.createSocke tForJDBC3(
    at net.sourceforge.jtds.jdbc.SharedSocket.<init>(Shar
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(C

    I don't think I'm leaking connections as I thought spring closed up connections for you as long as your running in a transaction. My Dao's all extend HibernateDaoSupport.
    I've used spring hibernate combination countless times with MySQL and oracle and never had these sorts of issues. Not sure if its the way my application is configured or something related to sqlserver database. I've read many related problems in various forums and was wondering if there is a recommended approach with sql server?
    I'm using the following:
    Hibernate -
    spring - 2.5.3
    c3po -

  • #2
    1) You are using hibernate so use the HibernateTransactionManager!
    2) Make sure you have PROPER transaction demarcation
    3) Make sure you don't open sessions yourself but let spring handle this. (i.e. sessionFactory.getCurrentSession instead of sessionfactory.openSession).

    Next time please use [ code][/code ] tags when posting code.


    • #3
      Yeah I noticed that I was using the wrong transaction manager shortly afterwards. Dohl!
      Thanks for this