表“XXXXX”未找到; SQL语句:

时间:2014-04-14 08:04:38

标签: sql hibernate grails

执行grails run-app时出错了。这是dataSource.groovy中的代码:

// environment specific settings
environments {
    development {
        dataSource {
            driverClassName = "org.postgresql.Driver"
            dialect = org.hibernate.dialect.PostgreSQLDialect
            username = "xxxxx"
            password = "xxxxx"
            dbCreate = "update" // one of 'create', 'create-drop', 'update','validate', ''
            url = "jdbc:postgresql://localhost:5432/grailsdev"
       }
    }

    test {
        dataSource {
            driverClassName = "org.h2.Driver"
            username = "sa"
            password = ""
            dbCreate = "update"
            url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
        }
   }
    ...
}

这是执行grails-app后的错误:

| Error 2014-04-14 15:47:36,788 [http-bio-8080-exec-3] ERROR util.JDBCExceptionReporter  - Table "PATH_SEED" not found; SQL statement:
select pathseed0_.id as id0_0_, pathseed0_.seed as seed0_0_ from path_seed pathseed0_ where pathseed0_.id=? for update [42102-173]
| Error 2014-04-14 15:47:36,798 [http-bio-8080-exec-3] ERROR errors.GrailsExceptionResolver  - JdbcSQLException occurred when processing request: [GET]  /fax-preview-grails/
Table "PATH_SEED" not found; SQL statement:
select pathseed0_.id as id0_0_, pathseed0_.seed as seed0_0_ from path_seed pathseed0_ where pathseed0_.id=? for update [42102-173]. Stacktrace follows:
Message: Table "PATH_SEED" not found; SQL statement:
select pathseed0_.id as id0_0_, pathseed0_.seed as seed0_0_ from path_seed pathseed0_ where pathseed0_.id=? for update [42102-173]
Line | Method
->>  331 | getJdbcSQLException       in org.h2.message.DbException
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    171 | get                       in     ''
|    148 | get . . . . . . . . . . . in     ''
|   4864 | readTableOrView           in org.h2.command.Parser
|   1107 | readTableFilter . . . . . in     ''
|   1713 | parseSelectSimpleFromPart in     ''
|   1821 | parseSelectSimple . . . . in     ''
|   1707 | parseSelectSub            in     ''
|   1550 | parseSelectUnion . . . .  in     ''
|   1538 | parseSelect               in     ''
|    405 | parsePrepared . . . . . . in     ''
|    279 | parse                     in     ''
|    251 | parse . . . . . . . . . . in     ''
|    218 | prepareCommand            in     ''
|    428 | prepareLocal . . . . . .  in org.h2.engine.Session
|    377 | prepareCommand            in     ''
|   1138 | prepareCommand . . . . .  in org.h2.jdbc.JdbcConnection
|     70 | <init>                    in org.h2.jdbc.JdbcPreparedStatement
|    267 | prepareStatement . . . .  in org.h2.jdbc.JdbcConnection
|     18 | doCall                    in   com.synacy.PathGeneratorService$_getNextSeed_closure1
|    712 | withTransaction . . . . . in org.grails.datastore.gorm.GormStaticApi
|     17 | getNextSeed               in com.synacy.PathGeneratorService
|      9 | getNextPath . . . . . . . in     ''
|     11 | index                     in com.synacy.HomeController
|    200 | doFilter . . . . . . . .  in 

我尝试使用此解决方案Grails throws Table "xxx" not found,但问题就出现了。

2 个答案:

答案 0 :(得分:0)

在DataSource.groovy文件中尝试此代码。

hibernate {
  cache.use_second_level_cache = true
  cache.use_query_cache = true
 //cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
 cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
 }

 // environment specific settings
 environments {
     development {
        dataSource {
           dbCreate = "update" // one of 'create', 'create-drop','update'
           pooled = true
           driverClassName = "org.postgresql.Driver"
           url = "jdbc:postgresql://localhost:5432/db"
           username = "root"
           password = ""
           dialect = "org.hibernate.dialect.PostgreSQLDialect"
           properties { 
             validationQuery="select 1" 
             testWhileIdle=true 
             timeBetweenEvictionRunsMillis=60000
          } 
       }   
    }

答案 1 :(得分:0)

我正面临类似的问题。 看起来Groovy在执行查询之前将表和列名称大写。 尝试在映射中双引表名。