enabling grails hibernate filters

后端 未结 2 1426
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-07 03:16

Hi I am using the Grails filter plugin

I am trying to define a default filter as below

// Defined inside the Book entity
static hibernateFilters = {
         


        
2条回答
  •  难免孤独
    2021-01-07 04:12

    After a little digging around I have come up with a workaround for the above problem

    I basically extend the GrailsOpenSessionInViewFilter class

    public class OpenSessionInViewFilterExt extends GrailsOpenSessionInViewFilter{
    @Override
    protected Session getSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {
        Session session = super.getSession(sessionFactory);
        for (Object filterName : DefaultHibernateFiltersHolder.getDefaultFilters()) {
            session.enableFilter((String) filterName);
        }
        return session;
    }
    

    }

    I also have a entry in the web.xml

        
            OpenSessionInViewFilterExt
            com.nthdimenzion.hibernate.ext.OpenSessionInViewFilterExt
    
    
    
    
        OpenSessionInViewFilterExt
        /*
    
    

    Now each time a new session is created the default filters are enabled for it. I think this should work, however it'll be better if some change can be made in the zkgrails plugin or the hibernate filters plugin so that the two can co-exist in a single application :)

    Thanks

提交回复
热议问题