I have the following bootstrap class
import shoppingsolutionproject.Category;
import shoppingsolutionproject.Item
class BootStrap {
def dataSource
def init = { servletContext ->
new Category(description: 'Car').save()
new Category(description: 'Truck').save()
new Item(productNumber:1, name:"First Product", description: "This is the first product I'm adding for testing",
shippingCost: 4.99, url: '/first', retailPrice: 19.99, salePrice: 16.99, category: 'Car').save()
new Item(productNumber:2, name:"Second Product", description: "This is the second product I'm adding for testing",
shippingCost: 4.99, url: '/second', retailPrice: 19.99, category: 'Truck').save()
new Item(productNumber:3, name:"First/Second Product", description: "This is the first/second(so third) product I'm adding for testing",
shippingCost: 4.99, url: '/second', retailPrice: 17.99, category: 'Truck').save()
}
def destroy = {
}
}
when I startup grails though, I don't have the categories or Items pre-populated... any idea why?
Most likely you have validation errors.
The quickest way to verify this is to add failOnError: true
to your .save()
like this: .save(failOnError: true)
.
That should show you lots of things that are failing due to validation errors.