title: How to add new auto-generated primary key field into legacy table with Grails?
body: <p>I have a legacy table I'm trying to hook up with Grails. I'm going to simplify it's model to make things easier. There are 2 fields in the table: "NAME" which is of type string and "CPAR" which is of type Integer and acts like a table's ID (primary key).</p>
  
  <p>What I want to do is keep "CPAR" for backwards compatibility and insert a new field "ID" into the table that will be auto generated and actually be table's primary key.</p>
  
  <p>Here is my domain class:</p>
  
  <pre><code>Class Partners {
  
      Long id
      String name
      Integer cpar
  
      static mapping = {
          table "PARTNERS"
          version false
  
          columns {
              id column: "ID", generator: "sequence"
              name column: "NAME"
              cpar column: "CPAR"
          }
      }
  }
  </code></pre>
  
  <p>When I run this application it does create ID field in the table but all rows are populated with zeroes (The "ID" field is zero, not the whole row). When trying to access application via it's scaffolded web interface it gives me error: Cannot get property 'id' on null object. What I would like is to have those "ID" fields populated with proper values instead of zeroes. How can I accomplish this? Database I'm using is Firebird.</p>