title: Grails Gorm : Object references an unsaved transient instance
body: <p>I get the following Exception when saving an instance of Trip in Grails:</p>
  
  <blockquote>
    <p>2011-01-26 22:37:42,801 [http-8090-5]
    ERROR errors.GrailsExceptionResolver 
    - object references an unsaved transient instance - save the
    transient instance before flushing: Rower
    org.hibernate.TransientObjectException:
    object references an unsaved transient
    instance - save the transient instance
    before flushing: Rower</p>
  </blockquote>
  
  <p>The concept is simple: For a boattrip you need some rowers, a coxwain (is also a rower) and a boat:</p>
  
  <p>Trip looks like (shortened):</p>
  
  <pre><code>class Trip {
      Boat boat;
      Rower coxwain;
  
      static belongsTo = [Rower,Boat]
      static hasMany = [rowers:Rower]
  }
  </code></pre>
  
  <p>and Rower (shortened)</p>
  
  <pre><code>class Rower { 
      String firstname;
      String name;
      Rower reference;
  
      static hasMany = [trips:Trip];
      static mappedBy = [trips:"rowers"]
  }
  </code></pre>
  
  <p>The trip then is saved in the controller like:</p>
  
  <pre><code>def save = {
          def trip = new Trip(params)
  
          // adding Rowers to Trip
          if (params.rower instanceof String) {
              def r = Rower.get(params?.rower)
  
              if (r != null) {
                  trip.addToRowers(r)
              }
          } else {
              params?.rower?.each{
                  rowerid -&gt;
                  def r = Rower.get(rowerid)
                  log.info("rowerid (asList): " + rowerid)
                  if (r != null) {
                      trip.addToRowers(r)
                  }
              }
          } 
  
          // saving the new Trip -&gt; EXCEPTION IN NEXT LINE
          if(!trip.hasErrors() &amp;&amp; trip.save(flush:true)) {
            // ...
          }
          // ...
  }
  </code></pre>
  
  <p>I think I have set the relations between the domains correct.
  The Rower is not changed while it is added to the Trip. Why does Grails want it to save? why is it a transient instance?</p>