2009-01-12 16 views
0

我在春天使用的HibernateDaoSupport對Spring-Hibernate集成到呼叫攔截到的getCurrentSession。我需要攔截所有getCurrentSession調用並啓用過濾器並設置過濾器參數值。如何使用CurrentSessionContext/SpringSessionContext用的HibernateDaoSupport沿()

Hibernate支持CurrentSessionContext impls來攔截getCurrentSession調用。 Spring提供了一個名爲SpringSessionContext的實現。但是當使用HibernateDaoSupport時,Spring有自己的SessionHolder機制,並且getCurrentSession()永遠不會被調用,攔截也不會起作用。有沒有解決方法?

回答

1

如果您正在使用AnnotationSessionFactoryBean或隨後的LocalSessionFactoryBean 你還需要設置該屬性:

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

默認情況下是真實的,當它是真的被忽略的hibernate.current_session_context_class屬性。

相關問題