Hibernate 如何正确使用SessionFactory.getCurrentSession()?

Hibernate 如何正确使用SessionFactory.getCurrentSession()?,hibernate,session,sessionfactory,Hibernate,Session,Sessionfactory,为什么这个单元测试失败了?它在同一个线程中,那么为什么getCurrentSession返回两个不同的会话呢 我在hibernate.cfg.xml中将“当前会话上下文类”设置为“线程”,如下所示 @Test public void testGetCurrentSession(){ Session firstSession=HibernateUtil.getSessionFactory().getCurrentSession(); Session secondSession=

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

我在hibernate.cfg.xml中将“当前会话上下文类”设置为“线程”,如下所示

@Test
public void testGetCurrentSession(){

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

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

    assertEquals(firstSession,secondSession);
}
ps:hibernate版本是4.0.1


任何帮助都将不胜感激

哪一个错误给了你答案?他们不平等吗?您能展示一下您的hibernate配置,看看SessionFactory是如何构建的吗?您会看到哪个错误?他们不平等吗?您能展示一下您的hibernate配置,看看SessionFactory是如何构建的吗?
<property name="current_session_context_class">thread
</property>