2
@Test
public void testGetCurrentSession(){

    Session firstSession=HibernateUtil.getSessionFactory().getCurrentSession();

    Session secondSession=HibernateUtil.getSessionFactory().getCurrentSession();

    assertEquals(firstSession,secondSession);
}

为什么这个单元测试会失败?它在同一个线程中,那么为什么 getCurrentSession() 返回两个不同的会话?

我在 hibernate.cfg.xml 中将“ current_session_context_class ”设置为“ thread ”,如下所示

<property name="current_session_context_class">thread
</property>

ps:休眠版本是4.0.1。

任何帮助将不胜感激!

4

0 回答 0