The Grails code below throws the following exception when trying to .save()
the Foo object:
org.hibernate.TransientObjectException/
org.springframework.dao.InvalidDataAccessApiUsageException:
object references an unsaved transient instance -
save the transient instance before flushing: Bar
I guess I'm missing out on some of the GORM semantics in connection with automatically populating domain objects from HTTP params.
My question is simply:
- What is the correct way to populate and save the Foo object, without getting said exception?
Model:
class Foo {
Bar bar
}
View:
<g:form id="${foo.id}">
<g:select name="foo.bar.id" from="${Bar.list()}" />
</g:form>
Controller:
class FooController {
def fooAction = {
Foo foo = new Foo(params)
foo.save()
[ foo: foo ]
}
}