4

所以我有一些简单的域类,我确保它们没有使用任何 PostgreSQL(或任何其他供应商,就此而言)保留字。执行grails schema-export会产生一个 ddl,当对同一个数据库运行时,它会成功执行,并毫无问题地创建所有表。

但是,在运行我的 grails 应用程序时,我收到错误消息ERROR: relation "artist" does not exist。(艺术家是我试图在 BootStrap.groovy 中创建样本的域)。

查看我的数据库,我可以看到没有为我的域创建任何表。

我已启用所有日志记录org.hibernate,但没有任何迹象表明有任何问题。我能看到的唯一问题是没有与任何表的创建相关的日志记录,只有简单选择的示例查询。

这是我的 DataSource.groovy:

dataSource {
    pooled = true
    driverClassName = "org.postgresql.Driver"
    dialect = "org.hibernate.dialect.PostgreSQLDialect"
    username = "my_username"
    password = "my_password"
}
hibernate {
    cache.use_second_level_cache = false
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
    development {
        dataSource {
            dbcreate = "create-drop"
            url = "jdbc:postgresql://localhost:5432/dev"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:postgresql://localhost:5432/test"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:postgresql://localhost:5432/prod"
            pooled = true
            properties {
               maxActive = -1
               minEvictableIdleTimeMillis=1800000
               timeBetweenEvictionRunsMillis=1800000
               numTestsPerEvictionRun=3
               testOnBorrow=true
               testWhileIdle=true
               testOnReturn=true
               validationQuery="SELECT 1"
           }
       }
    }
}

我已经验证了凭据(上面的假冒)是有效的,用户有权限,数据库在指定的位置运行,等等。

是否有任何我遗漏的内容,或者我可以启用的任何其他类型的日志记录可能会显示错误是什么,或者有助于找到它?

我觉得最好奇的是,生成的 ddlschema-export运行得很好。grails 在运行时是否会以不同的方式生成 SQL,或者是否有任何东西会导致 grails 不执行任何 create 语句?

Grails 版本 2.1.1,PostgreSQL 9.2.1

根据要求引导:

import my.site.domain.artist.*

class BootStrap {

    def init = { servletContext ->
        System.out.println("\n")
        log.info("---------------------------------------------------")
        log.info("BootStrap initializing...")
        log.info("---------------------------------------------------")
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
        log.info("Default TimeZone set to " + TimeZone.getDefault().displayName)

        Artist artist = new Artist(artistName: 'Artist Name', shortBio: "Short Bio", biography: "Bio", url: "/some_artist")

        artist.save()
        if(artist.hasErrors()) {
            log.info(artist.errors)
        } else {
            log.info("--Artist--")
            log.info("dateCreated: " + artist.dateCreated)
            log.info("lastUpdated: " + artist.lastUpdated)
            log.info("mediumImageURL: " + artist.mediumImageURL)
        }
    }

    def destroy = {
    }
}
4

1 回答 1

3

它可能是 pgsql 和 gorm 的特性,因为它与 ID 的自动生成序列以及 id 是 pgsql 中的保留字有关。确保在您的域对象中使用类似 user_id(具有适当的表语法)而不是 id。

于 2012-10-25T03:33:50.007 回答