title: Grails. Id is null after calling save
body: <p>I've already searched about this, but still cannot figure out what I'm doing wrong. After calling <code>save()</code> the domain object <code>id</code> is <code>null</code>. </p>
  
  <p>I've read it'll happen if there's a problem when saving the object, and that <code>save(flush:true)</code> should throw an error if that's the case, but it's not. Look at my code and the output:</p>
  
  <pre><code>def pic = new Picture(title:'XX', path:"XXX")
  album.addToPictures(pic).save()
  if(pic.validate())
     println "no errors. New id: " + pic.id
  else
     println "with errors"
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>no errors. New id: null
  </code></pre>
  
  <p>And when using flush:true</p>
  
  <pre><code>def pic = new Picture(title:'XX', path:"XXX")
  album.addToPictures(pic).save(flush:true)
  if(pic.validate())
     println "no errors. New id: " + pic.id
  else
     println "with errors"
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>no errors. New id: 17
  </code></pre>
  
  <p>As you can see, there aren't any errors creating the object, and I should be able to get the <code>id</code> of the object after just calling <code>save()</code>. Any ideas?</p>
  
  <p>Thanks</p>