Take the 2-minute tour ×

The Grails code below throws the following exception when trying to .save() the Foo object:

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?


class Foo {
  Bar bar


<g:form id="${foo.id}">
  <g:select name="foo.bar.id" from="${Bar.list()}" />


class FooController {
  def fooAction = {
    Foo foo = new Foo(params)
    [ foo: foo ]
share|improve this question

1 Answer 1

up vote 4 down vote accepted

If 'Bar' only exists in the context of Foo, add the following line to Bar.groovy

class Bar {
   static belongsTo = Foo


If 'Bar' is used in other context, you might use in Foo.groovy

class Foo {
  Bar bar
  static mapping = {
	bar cascade:'all-delete-orphan'

share|improve this answer

Your Answer


