title: Grails hibernate many to many issue
body: <p>My Domain has a relationship as per this:</p>
  
  <pre><code>class Offices {
  
  String officeLocation
  String officeName
  
  static belongsTo = Department
  static hasMany = [departments:Department, employees:Employee]
  
  }
  </code></pre>
  
  <p>When the user is on the page that allows them to add and remove location this is done by loading templates multiple times depending on the users choice. When the user hits "Add Location" I need to make sure the instance remains. My function in the controller:</p>
  
  <pre><code>def addLocation() {
  
  def officesInstance = new Offices(officeLocation: params.officeLocation, officeName: params.officeName)
  
  render template: "form" , model: [officesInstance: officesInstance]
  
  }
  </code></pre>
  
  <p>view code:</p>
  
  <pre><code>&lt;g:each var="entry" in="${departmentList}"&gt;
  
              &lt;div class="control-group fieldcontain"&gt;
                  &lt;label class="bold" for="department"&gt;
                      &lt;g:message code="department.locked.label" default="${entry.encodeAsHTML()}" /&gt;
                  &lt;/label&gt;
                  &lt;div class="controls form-field-align form-field-pad"&gt;
                      &lt;g:checkBox name="department_${entry}" value="${officesInstance.value}" /&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
          &lt;/g:each&gt;
  </code></pre>
  
  <p>The problem I'm having is I'm getting the following error when the addLocation function is pressed.</p>
  
  <blockquote>
    <p>| Error 2015-02-27 12:51:52,412 [http-bio-8080-exec-7]</p>
    
    <p>ERROR hibernate.AssertionFailure  - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
    Offices: null id in com.myapp.Offices entry (don't flush the Session after an exception occurs)</p>
    
    <p>Line | Method
       200 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter</p>
    
    <hr>
  
  <pre><code>63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
  53 | doFilter  in . grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
  49 | doFilter  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
  82 | doFilter  in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
  1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
  615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
  745 | run       in java.lang.Thread
  </code></pre>
    
    <p>| Error 2015-02-27 12:51:52,416 [http-bio-8080-exec-7]
    ERROR errors.GrailsExceptionResolver  - AssertionFailure occurred when processing request: [POST] /myapp/offices/addLocation - parameters:</p>
    
    <p>officeLocation: London</p>
    
    <p>formId: createForm</p>
    
    <p>elementToReplace: elementToReplace</p>
    
    <p>officeName: Office Name</p>
    
    <p>null id in com.smstool.Offices entry (don't flush the Session after an exception occurs). Stacktrace follows:
    Offices: null id in com.myapp.Offices entry (don't flush the Session after an exception occurs)
       Line | Method</p>
  
  <pre><code>-&gt;&gt;  200 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
  </code></pre>
    
    <hr>
  
  <pre><code>63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
  53 | doFilter  in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
  49 | doFilter  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
  82 | doFilter  in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
  1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
  615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
  745 | run       in java.lang.Thread
  </code></pre>
  </blockquote>