Hibernate/Spring: getHibernateTemplate().save(...) Freezes/Hangs

Posted by ashes999 on Stack Overflow See other posts from Stack Overflow or by ashes999
Published on 2011-01-08T17:48:30Z Indexed on 2011/01/08 22:54 UTC
Read the original article Hit count: 191

Filed under:
|
|
|
|

I'm using Hibernate and Spring with the DAO pattern (all Hibernate dependencies in a *DAO.java class). I have nine unit tests (JUnit) which create some business objects, save them, and perform operations on them; the objects are in a hash (so I'm reusing the same objects all the time).

My JUnit setup method calls my DAO.deleteAllObjects() method which calls getSession().createSQLQuery("DELETE FROM <tablename>").executeUpdate() for my business object table (just one).

One of my unit tests (#8/9) freezes. I presumed it was a database deadlock, because the Hibernate log file shows my delete statement last. However, debugging showed that it's simply HibernateTemplate.save(someObject) that's freezing. (Eclipse shows that it's freezing on HibernateTemplate.save(Object), line 694.)

Also interesting to note is that running this test by itself (not in the suite of 9 tests) doesn't cause any problems.

How on earth do I troubleshoot and fix this?

Also, I'm using @Entity annotations, if that matters.

Edit: I removed reuse of my business objects (use unique objects in every method) -- didn't make a difference (still freezes).

Edit: This started trickling into other tests, too (can't run more than one test class without getting something freezing)

Transaction configuration:

    <bean id="txManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <tx:advice id="txAdvice" transaction-manager="txManager">
        <!-- the transactional semantics... -->
        <tx:attributes>
            <!-- all methods starting with 'get' are read-only -->
            <tx:method name="get*" read-only="true" />
            <tx:method name="find*" read-only="true" />
            <!-- other methods use the default transaction settings (see below) -->
            <tx:method name="*" />
        </tx:attributes>
    </tx:advice>

    <!-- my bean which is exhibiting the hanging behavior -->
    <aop:config>
    <aop:pointcut id="beanNameHere"
        expression="execution(* com.blah.blah.IMyDAO.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="beanNameHere" />
</aop:config>

© Stack Overflow or respective owner

Related posts about mysql

Related posts about hibernate