Grails 抛出表“xxx"未找到 [英] Grails throws Table "xxx" not found

查看:25
本文介绍了Grails 抛出表“xxx"未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Grails 中,我可以在 BootStrap 的内存数据源中创建域对象到 H2 并返回正常结果,但是一旦应用程序启动(例如从 GSP 或控制器查询),我尝试运行我得到的一个查询:

In Grails I can create domain objects to a H2 in memory dataSource in BootStrap and get results back ok, but once the app is up (eg query from GSP or controller) and I try to run a query I get this:

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)

  • 我已经清理了构建

    • I have cleaned the build

      运行 Grails 2.0.0

      Running Grails 2.0.0

      我有多个数据源到 SQL 服务器数据库,这些数据源只调用StoredProcedures,现在已经找到了一个用例,可以使用旧的 Domain 对象在内存存储中使用 H2...错误只发生在
      域.

      I had multiple datasources to SQL servers DB's that only do calls to StoredProcedures and had now found a use case to use a H2 in memory store using good old Domain objects...the error only occurs on the
      domains.

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

      I ran the dbconsole and the only tables found are the standard 28
      "internal" tables...none are from my application

      一些来源:

      Datasource.groovy

      Datasource.groovy

      // "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:

      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_
      

      并返回所有正确的值.

      所以它就像在某处引导后内存标签被删除,但这没有被记录.

      So its like the in memory tabes are being dropped after bootstrap somewhere but this is not being logged.

      感谢任何帮助.

      谢谢,

      史蒂夫

      推荐答案

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

      H2 closes the database when the last connection is closed. For an in-memory database, closing the connection means the data is lost...

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

      So if you keep one connection open all the time, then you should be fine. You could call this a 'sentinel' connection.

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

      Another option is to use a persistent database (database URL jdbc:h2:~/test/app_data;MVCC=TRUE)

      这篇关于Grails 抛出表“xxx"未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆