Grails 关闭引用完整性的大容量删除域对象

Grails 关闭引用完整性的大容量删除域对象,grails,Grails,我正在尝试从禁用引用完整性的数据库中进行批量删除 def dc = grailsApplication.getArtefacts("Domain")*.clazz sessionFactory.currentSession.flush() def db = new Sql(dataSource) db.withBatch { stmt -> stmt.addBatch("SET FOREIGN_KEY_CHECKS = 0") dc.each { l

我正在尝试从禁用引用完整性的数据库中进行批量删除

def dc = grailsApplication.getArtefacts("Domain")*.clazz    
sessionFactory.currentSession.flush()
def db = new Sql(dataSource)
db.withBatch { stmt ->
    stmt.addBatch("SET FOREIGN_KEY_CHECKS = 0")
    dc.each {
        log.info(it.name)
        //if it is a domain a baseDomainClass
        if(it in tao.BaseDomainClass.class){
            //def tableName = GrailsDomainBinder.getMapping(it.getClass()).table.name
            log.info("in "+it.name)
            def tableName = GrailsDomainBinder.getMapping(it.getClass()).table.name
            stmt.addBatch("delete from table " + table_name+" where entity = '"+e+"'")
        }
    }
    stmt.addBatch("SET FOREIGN_KEY_CHECKS = 1")
}
sessionFactory.currentSession.clear()
这是我得到的例外:

Entity= tao.auth.Entity : 2
2014-08-09 10:01:07,859 [http-bio-8080-exec-7] ERROR errors.GrailsExceptionResolver  -     MissingMethodException occurred when processing request: [GET] /logging/deleteDomainObjectsByEntity - parameters:
entity: thomas
No signature of method: static     org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.getMapping() is applicable for argument types: (java.lang.Class) values: [class java.lang.Class]
Possible solutions: getMapping(java.lang.Class), getMapping(org.codehaus.groovy.grails.commons.GrailsDomainClass). Stacktrace follows:
groovy.lang.MissingMethodException: No signature of method: static     org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.getMapping() is applicable for argument types: (java.lang.Class) values: [class java.lang.Class]
Possible solutions: getMapping(java.lang.Class), getMapping(org.codehaus.groovy.grails.commons.GrailsDomainClass)
at     tao.logg.LoggingController$_deleteDomainObjectsByEntity_closure5_closure9.doCall(LoggingController.groovy:262)
at tao.logg.LoggingController$_deleteDomainObjectsByEntity_closure5.doCall(LoggingController.groovy:257)
at tao.logg.LoggingController.deleteDomainObjectsByEntity(LoggingController.groovy:255)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
基本上我需要的是从域对象获取表名

非常感谢您的帮助


提前感谢。

GrailDomainBinder.getMapping(it.clazz)不再是静态的(我相信从2.3开始)

而是创建一个新实例:

new GrailDomainBinder().getMapping(it.clazz)

此外,我认为您可能希望使用
it.clazz
而不是
it.class
(我可能对此有错误,但我相信前者将为您提供实际的底层域类)