Grails 如何禁用每个环境的gorm.mapping id生成
我在生产环境中使用oracle db,为此我在gorm中使用id generator by sequences进行映射 但是现在我只想在我使用hsqldb in文件的开发中禁用域的所有映射 这是为了不必为每台开发人员pc安装oracle 我曾在引导中尝试过:Grails 如何禁用每个环境的gorm.mapping id生成,grails,gorm,Grails,Gorm,我在生产环境中使用oracle db,为此我在gorm中使用id generator by sequences进行映射 但是现在我只想在我使用hsqldb in文件的开发中禁用域的所有映射 这是为了不必为每台开发人员pc安装oracle 我曾在引导中尝试过: import grails.util.GrailsUtil; class DevBootStrap { def grailsApplication def init = { servletContext ->
import grails.util.GrailsUtil;
class DevBootStrap {
def grailsApplication
def init = { servletContext ->
if(GrailsUtil.environment in ["development"]){
grailsApplication.domainClasses.each { domainClass ->
domainClass.metaClass.mapping = null
}
}
}
def destroy = {
}
}
但它不起作用
我也试过了
grails.gorm.default.mapping = null
而且也不起作用
我想可能是一些事件。但我不知道是哪件事
你能给我一个指针吗?我想这可能行得通,但是你需要添加
.clazz
,否则你在错误的班级里玩
grailsApplication.domainClasses.each { domainClass ->
domainClass.clazz.metaClass.mapping = null
}
我不确定您更改映射的时间点是否足够早。我发现您可以使用environment.current在域类映射中访问当前环境。因此,您可以在每个域类中尝试添加:
static mapping = {
if ( Environment.current != Environment.DEVELOPMENT ) {
//define mapping
}
}