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

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">
        <!-- 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>
+3
2

, . , , , .

, , . , , , .

? , .

hibernate.show_sql, SQL.

, . SQLServer sp_lock, , sp_who, , SQL .

+1

, :

  • - , DAO. , , DAO. - , , . @Transactional ( spring junit runner)

  • info (c3p0, ?). .

  • ( )

+1

Source: https://habr.com/ru/post/1784286/


All Articles