title: Problems with deleting objects in Grails - slow, and still not really deleted
body: <p>This is probably a rookie mistake, so forgive me in advance. I have searched high and low for a solution, but without result - so I thourght I'd add my first post here :-)</p>
  
  <p>I have two domain classes, one called Domain and one called Page. As below code shows, the Domain has many Page(s).</p>
  
  <pre><code>class Domain {
            ...
      static hasMany = [  pages : Page, ... ]
      static mapping = {
          pages lazy:true
      }
  }
  
  class Page {
      String identifier
      ...
      static belongsTo = [ domain : Domain ]
      static hasMany = [ ... ]
      static constraints = {
          identifier(blank:false, unique:'domain')
      }
      static mapping = {
          ...
          domain lazy:true
      }
  }
  </code></pre>
  
  <p>My application has a long algorithm that amongst other things creates Pages on a Domain. If you run the algorithm with the same arguments as a previous run, it will start by deleting all pages created by the previous run before running the algorithm again.</p>
  
  <p>I have two problems:</p>
  
  <p>Problem #1
  When I delete a specific Page from a Domain using:</p>
  
  <pre><code>def domain = page.domain
  domain.removeFromPages(page);
  page.delete()
  domain.save(flush:true)
  </code></pre>
  
  <p>This causes Hibernate to fetch and load all pages of the domain, which ultimately fires several thousands queries (the domain has MANY pages). How am I improving perfomance on this? - Executing sql directly to delete the page make the database and hibernate get out of sync.</p>
  
  <p>Problem #2
  When I later create the page again:</p>
  
  <pre><code>def page = new Page(identifier:'...').save(failOnError:true)
  </code></pre>
  
  <p>I get the: </p>
  
  <pre><code>org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session
  </code></pre>
  
  <p>Any help is welcome - I am losing my mind here :-/</p>