hibernate - Unable to enable filter in spring mvc interceptor -


i'm writing multenant application. i've following user entity:

    @entity     @filterdef(name="bytenantidfilter", parameters={     @paramdef( name="tenantid", type="long") }) @filter(name = "bytenantidfilter", condition = ":tenantid = tenant_id")     @table(name = "user_account")     public class user {          @column(name = "user_id")         @id         @generatedvalue(strategy = generationtype.auto)         long id;          @column(name = "login_id", unique = true)         string loginid; 

for enabling filter i've written interceptor fetches session, enables relevant filter , sets parameter tenantid.

following code of interceptor:

public class filterenablerinterceptor implements handlerinterceptor {    @autowired   private entitymanagerfactory entitymanagerfactory;    @override   public boolean prehandle(httpservletrequest request, httpservletresponse response, object handler)       throws exception {     authenticateduser user = (authenticateduser) securitycontextholder.getcontext().getauthentication().getprincipal();     sessionfactory sessionfactory = entitymanagerfactory.unwrap(sessionfactory.class);     session session = sessionfactory.opensession();     session.enablefilter("bytenantidfilter").setparameter("tenantid", user.gettenantid());     return true;   } 

however, filter query not appended final query being executed. probably, because session being used fetching results.

how can done ?


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -