Grails 抛出表“xxx”未找到
在 Grails 中,我可以在 BootStrap 中的内存数据源中创建 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服务器数据库只打电话给 StoredProcedures 现在已经找到了一个用例,可以使用良好的旧域对象在内存存储中使用 H2...该错误仅发生在
域。我运行了 dbconsole,唯一找到的表是标准 28
“内部”表...没有一个来自我的应用程序
一些来源:
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:
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_
并且返回所有正确的值。
因此,就像在引导后某处内存中的标签被删除一样,但这并没有被记录。
任何帮助表示赞赏。
谢谢,
史蒂夫
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 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.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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当最后一个连接关闭时,H2 关闭数据库。对于内存数据库来说,关闭连接意味着数据丢失......
因此,如果您始终保持一个连接打开,那么应该没问题。您可以将其称为“哨兵”连接。
另一种选择是使用持久数据库(数据库 URL
jdbc:h2:~/test/app_data;MVCC=TRUE
)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
)大多数内存数据库将数据库与所使用的连接联系起来。 Hibernate 为每个会话打开一个连接,因此只有具有 SchemaExport 的会话才拥有具有正确架构的数据库并立即处理。要解决此问题,您必须对访问内存数据库的所有会话使用相同的连接。
most inmemory database tie the database to the connection used. Hibernate opens a connection for each session so only the session with the SchemaExport has the database with the correct schema and is disposed immediatly. to solve this you have to use the same connection for all sessions which access the inmemory database.