使用Spring和Hibernate进行事务管理

时间:2012-02-05 15:02:22

标签: hibernate spring transactions

我们在Spring中有部分系统,部分系统不是基于Spring的。现在我们使用hibernate模板将所有调用都弃用到session.getCurrentSession。我们在Spring和非Spring系统中使用相同的会话工厂。为了将Hibernate事务管理绑定到单个线程,我们必须放置以下属性

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

然而Spring不喜欢它,并且为了Spring正常工作,它建议删除他以上的属性。它给出了一个例外,即它们不是活动事务。 Check this

如果我们删除它,那么非基于Spring的系统会抱怨我们不能使用getCurrentSession,因为我们还没有配置current_session_context_class属性。

现在我们正在使用Spring创建会话工厂,如下所示:

  <bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
   ...
  </bean>

对此有任何想法或想法。 提前谢谢。

0 个答案:

没有答案