0

我在 Spring 中使用 HibernateDaoSupport 进行 Spring-Hibernate 集成。我需要拦截所有 getCurrentSession 调用并启用过滤器并设置过滤器参数值。

Hibernate 支持 CurrentSessionContext 实现来拦截 getCurrentSession 调用。Spring 提供了一个名为 SpringSessionContext 的实现。但是当使用 HibernateDaoSupport 时,Spring 有自己的 SessionHolder 机制,并且 getCurrentSession() 永远不会被调用,并且拦截永远不会起作用。有解决方法吗?

4

2 回答 2

1

听起来您宁愿基于普通的 Hibernate 3 API 实现 Spring DAO:

http://static.springframework.org/spring/docs/2.5.x/reference/orm.html#orm-hibernate-straight

于 2009-01-12T17:22:23.023 回答
1

如果您使用的是 AnnotationSessionFactoryBean 或 LocalSessionFactoryBean 那么您还需要设置此属性:

<property name="exposeTransactionAwareSessionFactory" value="false" />

默认为true,当为true时,hibernate.current_session_context_class属性被忽略。

于 2009-01-13T14:50:06.093 回答