views:

1483

answers:

2

I'm using HibernateDaoSupport in Spring for Spring-Hibernate integration. I need to intercept all getCurrentSession calls and enable a filter and set a filter parameter value.

Hibernate supports CurrentSessionContext impls to intercept getCurrentSession calls. Spring provides an implementation of this called SpringSessionContext. But when using HibernateDaoSupport, Spring has it's own SessionHolder mechanism and getCurrentSession() never gets called and the interception never works. Is there a workaround for this?

+1  A: 

Sounds like you'd rather implement your Spring DAOs based on plain Hibernate 3 API:

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

duffymo
Spring provides support for Transaction synchronization in HibernateDaoSupport and avoids dangling sessions which is too hard to resist
Sathish
You can do declarative transactions in straight Hibernate. I'm not sure what "avoids dangling sessions" means here.
duffymo
+1  A: 

If you are using AnnotationSessionFactoryBean or LocalSessionFactoryBean then you also need to set this property:

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

By default is true, and hibernate.current_session_context_class property is ignored when it is true.

Banengusk