一尘不染

Grails抛出表“ xxx”未找到

hibernate

在Grails中,我可以在 BootStrap的
内存dataSource中创建到H2的域对象,并使结果恢复正常,但是一旦应用启动(例如,从GSP或控制器查询),然后尝试运行查询,我得到以下信息:

org.h2.jdbc.JdbcSQLException: Table "FUNCTIONAL_DOC_TYPE" not found; SQL statement:
select this_.id as id1_0_, this_.version as version1_0_, this_.direction_id as direction3_1_0_, this_.functional_group_id as functional4_1_0_, this_.type_name as type5_1_0_ from functional_doc_type this_ [42102-147]
 at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
 at org.h2.message.DbException.get(DbException.java:167)
 at org.h2.message.DbException.get(DbException.java:144)
 at org.h2.command.Parser.readTableOrView(Parser.java:4562)
 at org.h2.command.Parser.readTableFilter(Parser.java:1020)
 at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1622)
 at org.h2.command.Parser.parseSelectSimple(Parser.java:1729)
 at org.h2.command.Parser.parseSelectSub(Parser.java:1616)
 at org.h2.command.Parser.parseSelectUnion(Parser.java:1461)
 at org.h2.command.Parser.parseSelect(Parser.java:1449)
 at org.h2.command.Parser.parsePrepared(Parser.java:401)
 at org.h2.command.Parser.parse(Parser.java:275)
 at org.h2.command.Parser.parse(Parser.java:247)
 at org.h2.command.Parser.prepare(Parser.java:201)
 at org.h2.command.Parser.prepareCommand(Parser.java:214)
 at org.h2.engine.Session.prepareLocal(Session.java:425)
 at org.h2.engine.Session.prepareCommand(Session.java:374)
 at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1056)
 at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:71)
 at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:233)
 at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)
 at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:313)
 at org.grails.datastore.gorm.GormStaticApi.findAll(GormStaticApi.groovy:374)
  • 我已经清理了构建

  • 运行Grails 2.0.0

  • 我有多个SQL Server DB的数据源,这些数据源仅对StoredProcedures进行了调用,现在发现了一个用例,它使用良好的旧Domain对象在内存存储中使用H2 …该错误仅在
    域上发生。

  • 我运行了dbconsole,发现的唯一表是标准的28个
    “内部”表…没有一个来自我的应用程序

一些来源:

数据源

// "Parent" datasource def

dataSource_messages {
    pooled = true
    driverClassName = "net.sourceforge.jtds.jdbc.Driver"
    username = "user"
    password = "secret"
    readOnly = "true"
}


// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:h2:mem:app_data;MVCC=TRUE"
            pooled = true
            driverClassName = "org.h2.Driver"
            username = "sa"
            password = ""
            readOnly = false
        }
        dataSource_messages {
            url = "jdbc:jtds:sqlserver://localhost:1433;DatabaseName=Messages"
        }

域类:

class FunctionalDocType {
    String typeName
    FunctionalGroup functionalGroup
    DocDirection direction

    static constraints = {
        functionalGroup(nullable: true)
    }

}

Bootstrap.groovy:

   new FunctionalDocType(typeName: 'Order',   direction: buyerToSeller, functionalGroup: orders).save().save(flush: true)

   //  insert into functional_doc_type (id, version, direction_id, functional_group_id, type_name) values (null, ?, ?, ?, ?)


   FunctionalDocType.findAll() runs:

    // DEBUG SQL - select this_.id as id1_0_, this_.version as version1_0_, this_.direction_id as direction3_1_0_, this_.functional_group_id as functional4_1_0_, this_.type_name as     type5_1_0_ from functional_doc_type this_

并返回所有正确的值。

因此,就像在引导程序某个地方被删除后,将删除“内存中的标签”,但这并没有被记录下来。

任何帮助表示赞赏。

谢谢,

史蒂夫


阅读 207

收藏
2020-06-20

共1个答案

一尘不染

当最后一个连接关闭时,H2关闭数据库。对于内存数据库,关闭连接意味着数据丢失。

因此,如果您始终保持一个连接处于打开状态,那应该没问题。您可以将其称为“前哨”连接。

另一个选择是使用持久数据库(数据库URL jdbc:h2:~/test/app_data;MVCC=TRUE

2020-06-20