Setting a custom Hibernate session-scoped interceptor In Play 1.x does not work

495 views Asked by At

I want to specify a custom Hiberntate interceptor class for Playframework 1.5.3, is because I want to inspect all queries being issued and amend some of them as appropriate, in a global manner (can't use Hibernate @filter or @where for this case).

I added a custom Hibernate Interceptor class, which extends the play.db.jpa.HibernateInterceptor class, called HibernateQueryInterceptor. I put this in the app -> utils package.

The class:

package utils;

import play.db.jpa.HibernateInterceptor;

public class HibernateQueryInterceptor extends HibernateInterceptor {

    @Override
    public String onPrepareStatement(String arg0) {

        // Custom logic here

        return super.onPrepareStatement(arg0);
    }
}

I also added a property in application.conf to point to this class: hibernate.session_factory.session_scoped_interceptor=utils.HibernateQueryInterceptor

I can tell that Hibernate is picking up the property, because if I use the old (deprectaed) version of this property, I get a Hibernate warning about it in log during startup:

WARN org.hibernate.orm.deprecation:561 - HHH90000021: Encountered deprecated setting [hibernate.ejb.interceptor.session_scoped], use [hibernate.session_factory.session_scoped_interceptor] instead

There is an old pull request in the Play1 Github repo which also discusses this issue and suggests to use the session scoped interceptor property: https://github.com/playframework/play1/pull/888

From this pull request discussion and by inspecting the Play source code, I understand why a custom SessionFactory-scoped interceptor can't be specified (Play already sets one), but it seems that specifying a Session-scoped interceptor in this manner should work?

Any help on this will be much appreciated!

0

There are 0 answers