为什么Grails使用H2而不是Oracle?

时间:2012-08-27 11:09:25

标签: oracle grails controller h2

我花了很多时间来解决这个问题。我在GRAILS和GROOVY打招呼。 我有遗留的oracle数据库模式名为“tms_dev”。此架构有一些表(例如checktypes表)。我还有域类Checktype和ChecktypesController类 - 由GRAILS生成的控制器。

这个类有list方法:

def list(整数最大值){

params.max = Math.min(max ?: 10, 100)
[checktypesInstanceList: Checktypes.list(params), checktypesInstanceTotal: Checktypes.count()]

}

我还配置了Datasource.groovy文件以使用带有此类内容的oracle

dataSource {
    pooled = true
    driverClassName = "oracle.jdbc.OracleDriver"
    dialect = "org.hibernate.dialect.Oracle10gDialect"
    username = "TMS_DEV"
    password = "password"
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
development {
        dataSource {
            dbCreate = "update" // one of 'create', 'create-drop','update'
            url = "jdbc:oracle:thin:@server_name:1522:sid_name"
        }
    }
production {
        dataSource {
            dbCreate = "update" // one of 'create', 'create-drop','update'
            url = "jdbc:oracle:thin:@server_name:1522:sid_name"
        }
    }

我运行我的应用程序。然后在主页面上单击“tst7.ChecktypesController”refence。

结果我有例外:

| Error 2012-08-27 14:41:03,469 [http-bio-8080-exec-9] ERROR util.JDBCExceptionReporter  - Table "CHECKTYPES" not found; SQL statement:
select * from ( select this_.CHECKTYPECODE as CHECKTYP1_21_0_, this_.active as active21_0_, this_.availabilitychecktype as availabi3_21_0_, this_.checktypecode as checktyp1_21_0_, this_.checktypedescr as checktyp4_21_0_, this_.TARGETTYPECODE as TARGETTY5_21_0_ from CHECKTYPES this_ ) where rownum <= ? [42102-164]
| Error 2012-08-27 14:41:03,547 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver  - JdbcSQLException occurred when processing request: [GET] /Tst7/checktypes/list
Table "CHECKTYPES" not found; SQL statement:
select * from ( select this_.CHECKTYPECODE as CHECKTYP1_21_0_, this_.active as active21_0_, this_.availabilitychecktype as availabi3_21_0_, this_.checktypecode as checktyp1_21_0_, this_.checktypedescr as checktyp4_21_0_, this_.TARGETTYPECODE as TARGETTY5_21_0_ from CHECKTYPES this_ ) where rownum <= ? [42102-164]. Stacktrace follows:
Message: Table "CHECKTYPES" not found; SQL statement:
select * from ( select this_.CHECKTYPECODE as CHECKTYP1_21_0_, this_.active as active21_0_, this_.availabilitychecktype as availabi3_21_0_, this_.checktypecode as checktyp1_21_0_, this_.checktypedescr as checktyp4_21_0_, this_.TARGETTYPECODE as TARGETTY5_21_0_ from CHECKTYPES this_ ) where rownum <= ? [42102-164]
    Line | Method
->>  329 | getJdbcSQLException       in org.h2.message.DbException
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    169 | get                       in     ''
|    146 | get . . . . . . . . . . . in     ''
|   4753 | readTableOrView           in org.h2.command.Parser
|   1080 | readTableFilter . . . . . in     ''
|   1686 | parseSelectSimpleFromPart in     ''
|   1793 | parseSelectSimple . . . . in     ''
|   1680 | parseSelectSub            in     ''
|   1523 | parseSelectUnion . . . .  in     ''
|   1022 | readTableFilter           in     ''
|   1686 | parseSelectSimpleFromPart in     ''
|   1793 | parseSelectSimple         in     ''
|   1680 | parseSelectSub . . . . .  in     ''
|   1523 | parseSelectUnion          in     ''
|   1511 | parseSelect . . . . . . . in     ''
|    405 | parsePrepared             in     ''
|    279 | parse . . . . . . . . . . in     ''
|    251 | parse                     in     ''
|    217 | prepareCommand . . . . .  in     ''
|    415 | prepareLocal              in org.h2.engine.Session
|    364 | prepareCommand . . . . .  in     ''
|   1121 | prepareCommand            in org.h2.jdbc.JdbcConnection
|     71 | <init> . . . . . . . . .  in org.h2.jdbc.JdbcPreparedStatement
|    267 | prepareStatement          in org.h2.jdbc.JdbcConnection
|    281 | prepareStatement . . . .  in org.apache.commons.dbcp.DelegatingConnection
|    313 | prepareStatement          in org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
|     55 | <init> . . . . . . . . .  in grails.orm.PagedResultList
|     45 | list                      in tst7.ChecktypesController
|    195 | doFilter . . . . . . . .  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter                  in grails.plugin.cache.web.filter.AbstractFilter
|   1110 | runWorker . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
|    603 | run                       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . . . . . . . . . in java.lang.Thread

然后我尝试在列表方法

中创建直接Oracle连接
def list(Integer max) {

        def sql = Sql.newInstance("jdbc:oracle:thin:@server_name:1522:instance_name", "TMS_DEV",
            "password", "oracle.jdbc.driver.OracleDriver")
        sql.eachRow("select * from Dbdrivers"){
            println it.dbdrivercode
        }
}

比我运行应用程序。结果println it.dbdrivercode - 工作正常(CONNECTION WORKS !!!)。

这个问题最奇怪的是异常是由h2(内存数据库中的H2)类生成的(org.h2.jdbc.JdbcConnection ,org.h2.jdbc.JdbcConnection  等等)。

2 个答案:

答案 0 :(得分:2)

您违反了H2驱动程序,因为在环境块之外,生产开发块被忽略。

答案 1 :(得分:1)

听起来像应用程序缓存问题。在运行应用程序之前尝试运行grails clean。