问题描述
在Grails中,我可以在 BootStrap 中的内存dataSource中创建域对象,并获得结果,但一旦应用程序启动(例如,从GSP或控制器查询),并尝试运行一个查询我得到这个: org.h2.jdbc.JdbcSQLException:找不到表FUNCTIONAL_DOC_TYPE; SQL语句:
选择this_.id为id1_0_,this_.version为version1_0_,this_.direction_id为direction3_1_0_,this_.functional_group_id为functional4_1_0_,this_.type_name为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。在org.h2.command.Parser.readTableFilter(Parser.java:1020)处获得(DbException.java:144)
在org.h2.command.Parser.readTableOrView(Parser.java:4562)
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.engine.Session.prepareLocal(Session.java:425)
at org.h2.engine(org.h2english.com)$ b $ org.h2.command.Parser.prepareCommand(Parser.java:214)
.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.grails.datastore.gorm.GormStaticApi.findAll(GormStaticApi.groovy:374)$ b $ or $
$ $ b
-
我已经清除了构建
-
运行Grails 2.0.0
-
我有多个数据源到SQL服务器DB只能调用
StoredProcedures,并且现在已经找到一个用例来在使用良好的旧Domain对象的内存存储中使用H2 ...错误只发生在>
域名。 -
我运行了dbconsole,并且找到的唯一表格是标准的28 -
内部表格。 ..没有从我的申请
一些资料来源:
Datasource.groovy
//父数据源def
dataSource_messages {
pooled = true
driverClassName =net.sourceforge.jtds.jdbc.Driver
username =user
password =secret
readOnly =true
}
//环境特定设置
环境{
开发{
dataSource {
dbCreate =create-drop// 'create','create-drop','update','validate',''
url =jdbc:h2:mem:a pp_data; MVCC = TRUE
pooled = true
driverClassName =org.h2.Driver
username =sa
password =
readOnly = false
dataSource_messages {
url =jdbc:jtds:sqlserver:// localhost:1433; DatabaseName = Messages
}
域类:
类FunctionalDocType {
String typeName
FunctionalGroup functionalGroup
DocDirection方向
静态约束= {
functionalGroup(可为空):
}
}
Bootstrap.groovy:
new FunctionalDocType(typeName:'Order',方向: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()运行:
// DEBUG SQL - 选择this_.id作为id1_0_,this_.version作为version1_0_,this_.direction_id作为direction3_1_0_,this_.functional_group_id as functional4_1_0_,this_.type_name as type5_1_0_ from functional_doc_type this_
并返回所有正确的值。
所以它就像内存tabes在bootstrap之后被丢弃,但是这不会被记录下来。
。
谢谢,
Steve
解决方案H2在上次连接关闭时关闭数据库。对于内存中的数据库,关闭连接意味着数据丢失了......
因此,如果您始终打开一个连接,那么您应该没问题。你可以把它叫做'sentinel'连接。另一个选择是使用持久数据库(数据库URL
jdbc:h2:〜/ test / app_data; MVCC = TRUE
)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
Running Grails 2.0.0
I had multiple datasources to SQL servers DB's that only do calls toStoredProcedures 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.I ran the dbconsole and the only tables found are the standard 28
"internal" tables...none are from my application
Some source:
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"
}
Domain class:
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_
and all correct values are returned.
So its like the in memory tabes are being dropped after bootstrap somewhere but this is not being logged.
Any help appreciated.
Thanks,
Steve
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.
Another option is to use a persistent database (database URL jdbc:h2:~/test/app_data;MVCC=TRUE
)
这篇关于Grails抛出表“xxx”未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!