facebook

SpringDAO, Hibernate, "Too many connections"

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #295647 Reply

    Hello,

    I have this problem: When I want to run more than 100 junit tests on my Spring Hibernate DAO “Too many connections” error appears. In log I can see “releasing JDBC connection” every time but I can run only 100 tests and then it will crashed. Could somebody explain me what I have to set additionaly.

    applicattionContext.xml:

    <bean id=”sessionFactory”
    class=”org.springframework.orm.hibernate3.LocalSessionFactoryBean”>
    <property name=”dataSource”>
    <ref bean=”appuzleDataSource” />
    </property>
    <property name=”mappingResources”>
    <list>
    <value>./resources/mappings/Unit.hbm.xml</value>
    </list>
    </property>
    <property name=”hibernateProperties”>
    <props>
    <prop key=”hibernate.dialect”>org.hibernate.dialect.MySQLInnoDBDialect</prop>
    <prop key=”hibernate.connection.release_mode”>auto</prop>
    </props>
    </property>
    </bean>

    <bean id=”UnitDAO” class=”sk.appuzle.dao.UnitDAO”>
    <property name=”sessionFactory”>
    <ref bean=”sessionFactory” />
    </property>
    </bean>

    Unit:

    public class Unit implements java.io.Serializable {

    private Long id;
    private String code;
    private String name;

    ……

    }

    UnitDAO:

    public class UnitDAO extends HibernateDaoSupport {

    public void save(Unit transientInstance) {
    log.debug(“saving Unit instance”);
    try {
    getHibernateTemplate().save(transientInstance);
    log.debug(“save successful”);
    } catch (RuntimeException re) {
    log.error(“save failed”, re);
    throw re;
    }
    }
    ……..
    }

    UnitDAOTest:

    public class UnitDAOTest extends TestCase {

    private Resource resource;
    private BeanFactory factory;
    private UnitDAO unitDAO;

    protected void setUp() throws Exception {
    super.setUp();
    resource = new FileSystemResource(“src/applicationContext.xml”);
    factory = new XmlBeanFactory(resource);
    unitDAO = (UnitDAO)factory.getBean(“UnitDAO”);
    }

    protected void tearDown() throws Exception {
    super.tearDown();
    resource = null;
    factory = null;
    unitDAO = null;
    }

    @Test
    public void testSave() {
    Unit unit = new Unit();
    unit.setCode(“code”);
    unit.setName(“name”);

    unitDAO.save(unit);
    Unit unitResult = unitDAO.findById(unit.getId());
    unitDAO.delete(unit);

    assertTrue(unit.equals(unitResult));
    }
    }

    AllTests:
    public class AllTests {

    public static Test suite() {
    TestSuite suite = new TestSuite(“Test for sk.appuzle.test”);
    //$JUnit-BEGIN$

    for (int i = 0; i < 105; i++) {
    suite.addTestSuite(UnitDAOTest.class);
    }

    //$JUnit-END$
    return suite;
    }
    }

    Log:
    07 mar 2009 20:07:22 — DEBUG — Opening Hibernate Session
    07 mar 2009 20:07:22 — DEBUG — opened session at timestamp: 12364528421
    07 mar 2009 20:07:22 — DEBUG — fetching initial value: select max(unit_id) from unit
    07 mar 2009 20:07:22 — DEBUG — about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
    07 mar 2009 20:07:22 — DEBUG — opening JDBC connection
    07 mar 2009 20:07:22 — DEBUG — select max(unit_id) from unit
    07 mar 2009 20:07:22 — DEBUG — first free id: 105
    07 mar 2009 20:07:22 — DEBUG — about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
    07 mar 2009 20:07:22 — DEBUG — aggressively releasing JDBC connection
    07 mar 2009 20:07:22 — DEBUG — releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
    07 mar 2009 20:07:22 — DEBUG — generated identifier: 105, using strategy: org.hibernate.id.IncrementGenerator
    07 mar 2009 20:07:22 — DEBUG — Eagerly flushing Hibernate session
    07 mar 2009 20:07:22 — DEBUG — processing flush-time cascades
    07 mar 2009 20:07:22 — DEBUG — dirty checking collections
    07 mar 2009 20:07:22 — DEBUG — Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
    07 mar 2009 20:07:22 — DEBUG — Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
    07 mar 2009 20:07:22 — DEBUG — listing entities:
    07 mar 2009 20:07:22 — DEBUG — sk.appuzle.dto.Unit{id=105, name=name, code=code}
    07 mar 2009 20:07:22 — DEBUG — about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
    07 mar 2009 20:07:22 — DEBUG — opening JDBC connection
    07 mar 2009 20:07:22 — DEBUG — insert into appuzle.unit (unit_code, unit_name, unit_id) values (?, ?, ?)
    07 mar 2009 20:07:22 — DEBUG — Executing batch size: 1
    07 mar 2009 20:07:22 — DEBUG — about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
    07 mar 2009 20:07:22 — DEBUG — skipping aggressive-release due to flush cycle
    07 mar 2009 20:07:22 — DEBUG — aggressively releasing JDBC connection
    07 mar 2009 20:07:22 — DEBUG — releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
    07 mar 2009 20:07:22 — DEBUG — Closing Hibernate Session
    07 mar 2009 20:07:22 — DEBUG — Opening Hibernate Session
    07 mar 2009 20:07:22 — DEBUG — opened session at timestamp: 12364528421
    07 mar 2009 20:07:22 — DEBUG — loading entity: [sk.appuzle.dto.Unit#105]
    07 mar 2009 20:07:22 — DEBUG — about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
    07 mar 2009 20:07:22 — DEBUG — opening JDBC connection
    07 mar 2009 20:07:22 — DEBUG — select unit0_.unit_id as unit1_2800_0_, unit0_.unit_code as unit2_2800_0_, unit0_.unit_name as unit3_2800_0_ from appuzle.unit unit0_ where unit0_.unit_id=?
    07 mar 2009 20:07:22 — DEBUG — about to open ResultSet (open ResultSets: 0, globally: 0)
    07 mar 2009 20:07:22 — DEBUG — result row: EntityKey[sk.appuzle.dto.Unit#105]
    07 mar 2009 20:07:22 — DEBUG — about to close ResultSet (open ResultSets: 1, globally: 1)
    07 mar 2009 20:07:22 — DEBUG — about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
    07 mar 2009 20:07:22 — DEBUG — aggressively releasing JDBC connection
    07 mar 2009 20:07:22 — DEBUG — releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
    07 mar 2009 20:07:22 — DEBUG — resolving associations for [sk.appuzle.dto.Unit#105]
    07 mar 2009 20:07:22 — DEBUG — done materializing entity [sk.appuzle.dto.Unit#105]
    07 mar 2009 20:07:22 — DEBUG — initializing non-lazy collections
    07 mar 2009 20:07:22 — DEBUG — done entity load
    07 mar 2009 20:07:22 — DEBUG — aggressively releasing JDBC connection
    07 mar 2009 20:07:22 — DEBUG — Eagerly flushing Hibernate session
    07 mar 2009 20:07:22 — DEBUG — processing flush-time cascades
    07 mar 2009 20:07:22 — DEBUG — dirty checking collections
    07 mar 2009 20:07:22 — DEBUG — Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
    07 mar 2009 20:07:22 — DEBUG — Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
    07 mar 2009 20:07:22 — DEBUG — listing entities:
    07 mar 2009 20:07:22 — DEBUG — sk.appuzle.dto.Unit{id=105, name=name, code=code}
    07 mar 2009 20:07:22 — DEBUG — aggressively releasing JDBC connection
    07 mar 2009 20:07:22 — DEBUG — Closing Hibernate Session
    07 mar 2009 20:07:22 — DEBUG — Opening Hibernate Session
    07 mar 2009 20:07:22 — DEBUG — opened session at timestamp: 12364528421
    07 mar 2009 20:07:22 — DEBUG — Eagerly flushing Hibernate session
    07 mar 2009 20:07:22 — DEBUG — processing flush-time cascades
    07 mar 2009 20:07:22 — DEBUG — dirty checking collections
    07 mar 2009 20:07:22 — DEBUG — Flushed: 0 insertions, 0 updates, 1 deletions to 1 objects
    07 mar 2009 20:07:22 — DEBUG — Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
    07 mar 2009 20:07:22 — DEBUG — listing entities:
    07 mar 2009 20:07:22 — DEBUG — sk.appuzle.dto.Unit{id=105, name=name, code=code}
    07 mar 2009 20:07:22 — DEBUG — about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
    07 mar 2009 20:07:22 — DEBUG — opening JDBC connection
    07 mar 2009 20:07:22 — DEBUG — delete from appuzle.unit where unit_id=?
    07 mar 2009 20:07:22 — DEBUG — Executing batch size: 1
    07 mar 2009 20:07:22 — DEBUG — about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
    07 mar 2009 20:07:22 — DEBUG — skipping aggressive-release due to flush cycle
    07 mar 2009 20:07:22 — DEBUG — aggressively releasing JDBC connection
    07 mar 2009 20:07:22 — DEBUG — releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
    07 mar 2009 20:07:22 — DEBUG — Closing Hibernate Session

    #295687 Reply

    Loyal Water
    Member

    Moving to Off Topic >> Software Development.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: SpringDAO, Hibernate, "Too many connections"

You must be logged in to post in the forum log in