title: Save List of numbers in domain model error?
body: <p>I am currently trying to save a List of numbers associated to a domain model in Grails and I keep getting errors. So the scenario is:</p>
  
  <p>I have a Client Domain Model that is shown below and this has a HasMany relationship with a PhoneNumbers Domain model that is also shown below. There is a view where a bunch of numbers are added and then these are stored in a String [] for processing on the controller.</p>
  
  <p><strong>Client Domain:</strong></p>
  
  <pre><code>class Client {
  
      String name
  
      List numbers = new ArrayList()
  
      //This represents a message belonging to a single department
      static hasMany = [numbers:PhoneNumbers]
  
      static constraints = {
          name(blank:false)
      }
  
  
  }
  </code></pre>
  
  <p><strong>Phone Numbers Domain:</strong></p>
  
  <pre><code>class PhoneNumbers {
  
      String number
  
      //This represents a message belonging to a single department
      static belongsTo = [client:Client]
  
      static constraints = {
          number(blank:false)
      }
  
  
  }
  </code></pre>
  
  <p>As you can see the Client hasMany Phone Numbers and the Phone Numbers belongTo a Client. So in my controller I presumed all's I would need to do is to pass these numbers to the Domain in an Array or List and it would handle the cascade save, my controller function is below:</p>
  
  <pre><code>//This is an array of phone numbers stored in a sesson object as String []
          def numbers = session.getAttribute("phoneNumbers")
  
          def numbersConvert = numbers as List
  
          def client = new Client(numbers: numbersConvert, name: params.name)
  
          if (!client.save()) {
              client.errors.each{
                  println(it)
              }
          }
  </code></pre>
  
  <p>so the controller above I would expect to take the array of numbers which I have confirmed has values and then convert that to a List. Then save the new Client data and cascade save all the numbers that that client has in the List. However this does not work and I get the error below:</p>
  
  <pre><code>GRAILS-7799: Subtype 'java.lang.String' of reloadable type com.tool.PhoneNumbers is not reloadable: may not see changes reloaded in this hierarchy (please comment on that jira)
  | Error 2013-07-30 07:56:50,831 [http-bio-8080-exec-4] ERROR property.BasicPropertyAccessor  - IllegalArgumentException in class: com.smstool.PhoneNumbers, getter method of property: id
  | Error 2013-07-30 07:56:50,836 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResolver  - IllegalArgumentException occurred when processing 
  object is not an instance of declaring class. Stacktrace follows:
  Message: object is not an instance of declaring class
  </code></pre>
  
  <p>I did also try another approach to the save the data within the controller as shown below however this did not work either:</p>
  
  <pre><code>numbers.each{
  
              def phoneNumber = new PhoneNumber(number: it).save(flush: true)
  
              client.addToPhoneNumber(phoneNumber).save(flush: true)
  
          }
  </code></pre>
  
  <p>I presume I am missing something silly and this is probably a really easy thing to do just so tired and need a little help.</p>
  
  <p>Thanks in advance</p>