[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3890) Criteria and Query "Interceptor"

Eric Martineau (JIRA) noreply at atlassian.com
Thu Apr 30 02:58:17 EDT 2009


Criteria and Query "Interceptor"
--------------------------------

                 Key: HHH-3890
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3890
             Project: Hibernate Core
          Issue Type: Improvement
          Components: core, query-criteria, query-hql
            Reporter: Eric Martineau


It would incredibly useful to be able to intercept every Criteria and Query instance created by a Session.  It would allow you to enforce a filter that you wanted to be run on EVERY query to the database.

For example, if you each record in your system had a tenantId and you want to globally restrict queries to only include records for the current tenant:

public class TenantCriteriaInterceptor implements CriteriaInterceptor {
    public void intercept(Criteria criteria) {
        criteria.add(Expression.eq("tenantId", CurrentTenant.get()));
    }
} 

This type of functionality would be pretty easy to implement as an add-on to hibernate IF it were possible to extend SessionFactoryImpl.  I attempted to implement by using wrap/delegate, but I ran into a bunch of problems with Spring not being able to locate the Session bound to the current thread (sometimes it would try to locate the current session using the wrapped SessionFactoryImpl, sometimes it would use the wrapper).

I have this working perfectly by using a custom hibernate (3.3.1) where SessionFactoryImpl is NOT marked final.  I've exhausted all other avenues without any luck - any help would be appreciated.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list