gpt4 book ai didi

sql-server - Grails dbCreate ='validate'无法识别现有表

转载 作者:行者123 更新时间:2023-12-02 14:03:25 24 4
gpt4 key购买 nike

我将dataSource配置如下:

development {
dataSource {
dbCreate = "validate"
url = "jdbc:sqlserver://myservername"
}
}

我的SQL Server“myservername”有一个数据库“products”,其表“inventory”归“dbo”所有。这是我的 list 类映射:
static mapping = {
table 'products.dbo.inventory'
version false
columns {
id column: 'itemKey'
itemId column: 'itemId'
inactive column: 'inactive'
}
}

当我尝试运行该应用程序时,出现以下错误:

嵌套的异常是org.hibernate.HibernateException:缺少表:products.dbo.inventory

另外,当我将dbCreate从“validate”更改为“update”或任何其他更新时,它可以正常工作。

有什么想法吗?

提前致谢,
ud子

编辑以回答问题-

我将更改合并到对象中,但仍然收到错误。这是我的对象:
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

最佳答案

我相信这里的Hibernate没有办法看到如何生成主键。

我会尝试:

  • id字段更改为IDENTITY
  • 或/和调整 id field mapping以使用Java端generator
  • ,或更简单的方法是,尝试使用dbCreate = "create"和适当的权限连接到测试数据库,查看Hibernate将创建的表结构,并将表更改为该表。

  • 如果您需要保持表结构完整,则只有第二种方法。

    关于sql-server - Grails dbCreate ='validate'无法识别现有表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11851217/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com