Grails 2.3.4数据库视图作为域类

时间:2014-01-31 04:29:31

标签: grails gorm

我正在尝试使用数据库视图作为域类,遵循Burt Beckwith幻灯片中的步骤。

http://www.slideshare.net/gr8conf/gorm-burt-beckwith2011

我已经定义了配置类:

configClass = 'sfgroups.DdlFilterConfiguration'

package sfgroups

import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration

class DdlFilterConfiguration extends GrailsAnnotationConfiguration  {
    private static final String[] IGNORED_NAMES={"v_fullname"}

    private boolean isIgnored(String command){
        command=command.toLowerCase()

        for( String table : IGNORED_NAMES ){
            if( command.startsWith("create table " + table + " ") ||
                command.startsWith("alter table " + table + " ") ||
                command.startsWith("drop table " + table + " ") ||
                command.startsWith("drop table if exists " + table + " ")   ){
                return true
            }
        }
        return false
    }

}

域类

package com.sfg

class FullName {

    String firstname
    String lastname

    static mapping = {
        table = 'v_fullname'     
    }
}

当我运行应用程序时,它会给出此错误消息。

 ERROR context.GrailsContextLoader  - Error initializing the application: Error evaluating ORM mappings block for domain [com.sfg.FullName]:  No such property: table for class: org.codehaus.groovy.grails.orm.hibernate.cfg.HibernateMappingBuilder
Message: Error evaluating ORM mappings block for domain [com.sfg.FullName]:  No such property: table for class: org.codehaus.groovy.grails.orm.hibernate.cfg.HibernateMappingBuilder

如何修复此启动错误?

由于

2 个答案:

答案 0 :(得分:7)

使用

  static mapping = {
            table 'v_fullname'     
        }

而不是

static mapping = {
        table = 'v_fullname'     
    }

答案 1 :(得分:0)

使用此功能,需要添加版本false

static mapping = {
        table  'v_fullname'
        version false
    }
相关问题