Is it possible to explicitly specify the id of a domain object in Bootstrap.groovy Grails (or anywhere, for that matter)?
I 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 Foo.list()
at runtime, I see that my object is assigned identifier 1 or any next identifier in the sequence.
Edit:
This is in Grails 1.0.3, and when I run my application in "dev" with the built-in HSQL database.
Edit:
chanwit provided one good solution below . However, I was really looking for a way to set the identifier without changing the method of generating the domain identifier. This is primarily for testing: I would like to be able to set certain things in the values of known identifiers either in my test bootstrap or in setUp()
, but still be able to use auto_increment or sequence in the production process.
source
share