I use Hibernate and Spring with a DAO pattern (all Hibernate dependencies in the * DAO.java class). I have nine unit tests (JUnit) that create some business objects, save them, and perform operations on them; objects are in a hash (so I reuse the same objects all the time).
My JUnit installation method calls my method DAO.deleteAllObjects(), which calls getSession().createSQLQuery("DELETE FROM <tablename>").executeUpdate()for my business object table (only one).
One of my unit tests (# 8/9) freezes. I assumed that it was a database deadlock because the Hibernate log file shows my last delete expression. However, debugging showed that it is just HibernateTemplate.save(someObject)that it freezes. (Eclipse shows that it hangs on , line 694. ) HibernateTemplate.save(Object)
It is also interesting to note that running this test on its own (not in a set of 9 tests) does not cause any problems.
How can I troubleshoot and fix it?
In addition, I use annotations @Entityif that matters.
Edit: I removed the reuse of my business objects (using unique objects in each method) - has not changed (still freezes).
: ( - )
: . , un-DRY, -.
:
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="beanNameHere"
expression="execution(* com.blah.blah.IMyDAO.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="beanNameHere" />
</aop:config>