【发布时间】:2012-08-04 18:40:15
【问题描述】:
我的dataSource配置如下:
development {
dataSource {
dbCreate = "validate"
url = "jdbc:sqlserver://myservername"
}
}
我的 SQL Server“myservername”有一个数据库“products”,其中的一个表“inventory”归“dbo”所有。这是我的 Inventory 类映射:
static mapping = {
table 'products.dbo.inventory'
version false
columns {
id column: 'itemKey'
itemId column: 'itemId'
inactive column: 'inactive'
}
}
当我尝试运行应用程序时,我收到此错误:
嵌套异常是 org.hibernate.HibernateException: Missing table: products.dbo.inventory
此外,当我将 dbCreate 从“验证”更改为“更新”或任何其他时,它工作正常。
有什么想法吗?
提前致谢,
斯库德
编辑以回答问题 -
我将更改合并到我的对象中,但仍然出现错误。这是我的对象:
class Inventory {
Integer id
String itemId
String description
Boolean inactive
static mapping = {
table 'products.dbo.inventory'
version false
columns {
id column: 'itemKey'
itemId column: 'itemId'
description column: 'description'
inactive column: 'inactive'
}
}
static constraints = {
itemId (maxSize: 30)
description (maxSize: 100)
}
static hasMany = [productInventoryDefaults: ProductInventoryDefaults, productTreeNodes: ProductTreeNodes]
String toString() {
return this.itemId
}
}
和桌子:
CREATE TABLE [dbo].[inventory](
[itemKey] [int] NOT NULL,
[itemId] [varchar](30) NOT NULL,
[description] [varchar](100) NOT NULL,
[inactive] [bit] NOT NULL,
CONSTRAINT [PK_Inventory] PRIMARY KEY CLUSTERED
(
[itemKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
【问题讨论】:
-
Grails 实际上不会更改该表中的任何内容,也许是字段类型?域对象和表结构是什么?
-
你是说如果在“更新”模式下,Grails 试图改变一些东西(即使它失败了,因为它没有对 db 的 DDL 权限),那么它不会识别表的存在“验证”模式?因为对象和数据库表的列类型存在一些差异。
-
@VictorSergienko,我已经在我的原始帖子中包含了我的对象和表格。
-
没错。不是试图改变它,而是
"validate"意味着 Hibernate 将验证该表是否与 Hibernate 关于表的“想法”完全匹配:D
标签: sql-server grails datasource grails-orm