【问题标题】:Table "XXX" not found in Grails在 Grails 中找不到表“XXX”
【发布时间】:2016-03-03 20:35:17
【问题描述】:

尝试导入旧的 grails 项目,映射似乎有问题。一切都完美加载,直到...

Server running. Browse to http://localhost:8080/prmptvServer
Configuring Spring Security Core ...
... finished configuring Spring Security Core

| Error 2015-11-30 09:06:43,636 [localhost-startStop-1] ERROR hbm2ddl.SchemaExport  - HHH000389: Unsuccessful: alter table bank_account drop constraint FK_ss4uej5gx2a07srb540l15s21 if exists 
| Error 2015-11-30 09:06:43,638 [localhost-startStop-1] ERROR hbm2ddl.SchemaExport  - Table "BANK_ACCOUNT" not found; SQL statement: alter table bank_account drop constraint FK_ss4uej5gx2a07srb540l15s21 if exists [42102-176]

其他域也无法加载。据我了解,如果我的 DataSource 包含

dbCreate="create-drop"

,每次我重新启动应用程序时都应该重建数据库,不是吗?至少那是我记得的。那么如果它找不到表,它不是已经创建了吗?如果它没有在应该创建的时候创建,我不应该得到另一个错误,比如“无法创建表”吗?

Bootstrap.groovy 都被注释了,以便更容易地进行调试。

DataSource.groovy

dataSource {
    pooled = true
    jmxExport = true
    driverClassName = "org.h2.Driver"
    username = "sa"
    password = ""
}

hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
//    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
    cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
    singleSession = true // configure OSIV singleSession mode
    flush.mode = 'manual' // OSIV session flush mode outside of transactional context
}

// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
        }
    }...

BankAccount.groovy

class BankAccount {

    SecUser user
    String alias
    String number

    static constraints = {
        alias nullable: false, blank: false
        number nullable: false, blank: false
    }
}

【问题讨论】:

    标签: grails orm mapping h2


    【解决方案1】:

    我相信这不是一个严重的问题。我在我的项目中遇到了同样的错误,但应用程序仍然可以正常运行。

    我认为此配置存在一些不一致之处。不是关于你,而是关于圣杯。

    也许这篇文章回答了你的问题 -> here

    【讨论】:

      猜你喜欢
      • 2012-02-13
      • 2011-07-01
      • 2021-09-24
      • 2018-06-28
      • 2015-04-07
      • 1970-01-01
      • 2014-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多