title: Grails wrong alias causing error ORA-00904
body: <p>I have three domain classes <code>User</code>, <code>Employee</code> and <code>UserEmployee</code>.</p>
  <pre><code>class User {
      String username
      //more atributes omitted 
  
      static hasMany = [ userEmployees : UserEmployee ]
      static mapping = {
        version false
        table 'myUserTable'
         id column: 'username', name: 'username' 
      }
  }
  
  class Employee {
      long employeeCode
      //more atributes omitted 
      static hasMany = [ userEmployees : UserEmployee ]
      static mapping = {
         id column: 'myColumn', name: 'employeeCode' 
         version false
         table 'myViewHere'
      }
  }
  
  class UserEmployee implements Serializable {
      User user
      Employee employee
      static belongsTo = [ user : User,  employee : Employee ]
      static mapping = {
        version false
        table 'myRelationTable'
        id composite: ['user','employee']
        user(column: &quot;username&quot;)
        employee(column: &quot;myColumn&quot;)
      }
  }
  </code></pre>
  <p>When I try to query all the employees that some user can access, I get the ORA-00904 error:</p>
  <pre><code>println UserEmployee.withCriteria {
      projections {
         user {
             eq('username', 'SOMEUSER')
         }
      }
  }
  </code></pre>
  <p>The hibernate output is something like this:</p>
  <pre><code>Hibernate: select * from ( select this_.username as usuario27_0_, from myUserTable this_ where this_.username=? ) where rownum &lt;= ?
  
  Hibernate: select this_.username as usuario24_0_, this_.code_employee as cod2_24_0_ from myRelationalTable this_ where (usu_alias1x1_.username=?)
  </code></pre>
  <p>Why is the alias <code>usu_alias1x1_</code> created?</p>
  <p>P.S.: I changed the domain classes names and fields to better understanding. Maybe will be a typo somewhere.</p>
  <p><strong>EDIT</strong></p>
  <p>I'm mapping a database that already exists and cannot have the PK's changed to the Grails default. So I'm using the <code>id column</code> to declare the keys.</p>