Is it explicitly the domain object ID set in Grails' Bootstrap.groovy (or anywhere, for that matter) Is it possible to do?
I have tried the following:
New Foo (id: 1234, name: "my foo"). Save ()
and:
def foo = new Foo () foo.id = 1234 foo.name = "My Foo" foo.save ( )
But in both cases, when I print the results of Foo.list ()
on runtime, I think my object is 1 Has given the ID, or whatever sequence has the next ID.
Edit: This Grails is in 1.0.3, and when I am running my application in the 'H' database underlying HSQL database.
Edit: Chanwat has provided, however, I was actually exploring a way to set the ID without changing the domain of the ID of my domain. To test: I want to be able to set some test items either in my test bootstrap or setUp ()
, but still be able to use auto_increment or a sequence in production .
Yes, manually with GORM mapping:
class Foo {String Name Static Mapping = {ID Generator: 'Assign'}}
and your second snippet (not the first one) will be employed (ID will not be specified when passing it) .
Comments
Post a Comment