title: grails - afterDelete() accessing domain properties
body: <p>Assuming I have got the following domain class and its corresponding history domain class in order to automatically save any changes made to the original domain object:</p>
  
  <pre><code>@Entity
  class Product {
  
      String productName 
  
      static constraints = {
          productName maxSize: 250
      }
  
      def afterInsert() {
          History_Product hist = new History_Product(this)
          hist.insertType = 'I'
          History_Product.withNewSession {
              hist.save()
          }
      }
  
      def afterUpdate() {
          History_Product hist = new History_Product(this)
          hist.insertType = 'U'
          History_Product.withNewSession {
              hist.save()
          }
      }
  
      def afterDelete() {
          History_Product hist = new History_Product(this)
          hist.insertType = 'D'
          History_Product.withNewSession {
              hist.save()
          }
      }
  }
  
  @Entity
  class History_Product {
  
      String productName
      Char insertType
  
      static constraints = {
          productName nullable: true, maxSize: 250
      }
  
      History_Product() {}
  
      History_Product(Product p) {
          this.properties = p.properties
      }
  }
  </code></pre>
  
  <p>So, every time a <code>Product</code> object is created, updated or deleted a new <code>History_Product</code> is created in order to save the old value. This works like a charm for creating and updating. However, it doesn't work if I want to delete a product because then <code>p.properties</code> wihtin the second constructor of <code>History_Product</code> contains only <code>NULL</code> values. I don't know where the difference ist between the <code>afterInsert</code>, the <code>afterUpdate</code> and the <code>afterDelete</code> methods. I also tried to use the <code>beforeDelete</code> method in case of delete but without success.</p>
  
  <p>Any guesses?</p>
  
  <p>EDIT:</p>
  
  <p>I now checked if I can access the <code>properties</code> directly within <code>afterUpdate</code> or <code>afterDelete</code>. So I added <code>println this.properties</code> as first line in each of the two methods. Interestingly, that works find for <code>afterUpdate</code> but doesn't for <code>afterDelete</code>. What could be the reason? In my controller I've just put <code>productInstance.delete flush:true</code>.</p>
  
  <p>2nd EDIT:</p>
  
  <p>Most interestingly, within <code>afterDelete</code> I can retrieve the value of <code>productName</code>. No matter if I use only <code>productName</code> or <code>this.productName</code>. Hence, the object is not "empty". Anyway, I don't know why the <code>properties</code> map is <code>NULL</code>.</p>
  
  <p>3rd EDIT:</p>
  
  <p>I now added <code>println productInstance.properties</code> within the controllers <code>delete</code> action before I actually delete the <code>productInstance</code>. And with this it works. Does anyone has got some kind of explanation for this behaviour?</p>