Reputation: 1123
I have the dataSource configured as follows:
development {
dataSource {
dbCreate = "validate"
url = "jdbc:sqlserver://myservername"
}
}
My SQL Server "myservername" has a database "products" with a table "inventory" owned by "dbo". Here is my Inventory class mapping:
static mapping = {
table 'products.dbo.inventory'
version false
columns {
id column: 'itemKey'
itemId column: 'itemId'
inactive column: 'inactive'
}
}
When I try to run the app, I get this error:
nested exception is org.hibernate.HibernateException: Missing table: products.dbo.inventory
Also, when I change dbCreate from "validate" to "update" or any other ones, it works fine.
Any ideas why?
Thanks in advance,
Skudder
Edit to respond to question -
I merged the changes to my object and I still get the error. Here is my object:
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
}
}
and table:
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
Upvotes: 2
Views: 1163
Reputation: 13495
I believe here Hibernate has no means to see how to generate primary keys.
I'd try to either:
id
field to IDENTITY
;id
field mapping to use Java-side generator
;dbCreate = "create"
and proper permissions, see what table structure will Hibernate create, and alter your table to that one.If you need to retain the table structure intact, then only the second way is the way.
Upvotes: 2