启用 Grails 休眠过滤器
您好,我正在使用 Grails 过滤器插件
我正在尝试定义一个默认过滤器,如下
// Defined inside the Book entity
static hibernateFilters = {
activeFilter(condition:'active=1', default:true)
}
所示我运行集成测试,过滤器不适用于动态查找器方法,例如
Book.findAll()
如果我在 BootStrap.groovy 类中添加以下行,
Book.enableHibernateFilter('activeFilter')
则应用过滤器。
然而,当应用程序运行时,无论 BootStrap.groovy 中有或没有上述代码,过滤器都不会被应用。
有什么想法吗?
经过一番挖掘后,我发现
hibernate 过滤器插件在没有 zkgrails 插件的情况下也能很好地工作,但是两者似乎无法一起工作:(
下面的代码片段对我来说似乎是问题。
我认为我们可能有两个问题这里
1) 最初执行到
all(controller:'', action:'')
在应用程序启动期间仅执行一次。我认为每次有新的请求并因此有新的会话时它都应该到达那里。
2)即使它在某些修改后以某种方式到达那里,我也不认为它会过去 all(controller:'', action:'')作曲家
zkoss 中使用了
class HibernateFilterFilters {
def filters = {
all(controller:'*', action:'*') {
before = {
def session = grailsApplication.mainContext.sessionFactory.currentSession
DefaultHibernateFiltersHolder.defaultFilters.each {name ->
session.enableFilter(name)
}
}
after = {
}
afterView = {
}
}
}
}
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 = {
activeFilter(condition:'active=1', default:true)
}
When i run my integration tests the filter does not apply for dynamic finder methods like
Book.findAll()
If I add the below line in the BootStrap.groovy class
Book.enableHibernateFilter('activeFilter')
Then the filter is applied.
However when the application is run the filter is never applied, with or without the above code in BootStrap.groovy
Any ideas ?
After a little digging around this is what i have found
The hibernate filter plugin works well without the zkgrails plugin however the two cannot seem to work together :(
The below code snippet seems to be the problem for me.
I think we could have two issues here
1) Initially the execution gets to
all(controller:'', action:'')
only once during application startup. I am thinking it should get there each time there is a new request and hence a new session.
2) Even if it somehow gets there after certain modification, I do not think it'll get past
all(controller:'', action:'')
composers are used in zkoss
class HibernateFilterFilters {
def filters = {
all(controller:'*', action:'*') {
before = {
def session = grailsApplication.mainContext.sessionFactory.currentSession
DefaultHibernateFiltersHolder.defaultFilters.each {name ->
session.enableFilter(name)
}
}
after = {
}
afterView = {
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过一番挖掘后,我想出了解决上述问题的方法,
我基本上扩展了 GrailsOpenSessionInViewFilter 类
}
我还在 web.xml 中有一个条目
现在,每次创建新会话时,都会为其启用默认过滤器。我认为这应该可行,但是如果可以在 zkgrails 插件或 hibernate 过滤器插件中进行一些更改,以便两者可以在单个应用程序中共存:)
谢谢
After a little digging around I have come up with a workaround for the above problem
I basically extend the GrailsOpenSessionInViewFilter class
}
I also have a entry in the web.xml
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
在我的 Grails 2.5.X 应用程序中,我在 Web 过滤器中启用了休眠过滤器,即我在
grails-app/conf/Filters.groovy
中有此代码在插件本身的集成测试中, < a href="https://github.com/gpc/grails-hibernate-filter/blob/master/test/integration/org/grails/plugin/hibernate/filter/CollegeFilterSpec.groovy#L14L17" rel="nofollow">过滤器在测试类的设置方法中启用。
In my Grails 2.5.X app I enable the hibernate filters in a web filter, i.e. I have this code in
grails-app/conf/Filters.groovy
In the integration tests in the plugin itself, the filters are enabled in the setup method of the test class.