title: Grails criteria bug? with domain that has composite foreign key as id : Column "ALIAS2X2_.ID" not found
body: <p>Problem is with the following query. I want to list all the LI:s in L that contain an I with id 'I01'.</p>
  
  <p>query:</p>
  
  <pre><code>def c = L.withCriteria {
    lis {
      i {                   
        eq("id","I01")                                 
      }
    }
  }
  </code></pre>
  
  <blockquote>
    <p>Column "I_ALIAS2X2_.ID" not found; SQL statement: select this_.id as
    id4_1_, this_.version as version4_1_, lis_alias1x1_.i_id as i1_7_0_,
    lis_alias1x1_.l_id as l2_7_0_, lis_alias1x1_.version as version7_0_
    from l this_ inner join LI lis_alias1x1_ on
    this_.id=lis_alias1x1_.l_id where ((i_alias2x2_.id=?)) [42122-164]</p>
  </blockquote>
  
  <p>Is there something wrong in my criteria or are my domains not correct ? If I add 'long id' into LI domain and comment out the 'id: composite...' row then criteria runs ok. </p>
  
  <p>domains:</p>
  
  <pre><code>class L {
  long id   
  //can this hasMany be used here ? domain L is the other FK in LI domain
  static hasMany = [lis: LI]
  
  static mapping = {       
      lis: joinTable: false       
  }
  
  static constraints = {
  }
  }
  
  import org.apache.commons.lang.builder.HashCodeBuilder
  
  class LI implements Serializable {
  //domain has only FK:s to L and I
  
  static belongsTo = [l: L, i: I]
  
  static mapping= {
      table "LI"
      id composite:['i', 'l']
      i column: 'i_id'
      l column: 'l_id'       
  }
  
  static constraints = {
  }
  
  boolean equals(other) {        
      if (!(other instanceof LI)) { return false }       
      other.l == l &amp;&amp; other.i == i       
  }
  
  int hashCode() {        
      def builder = new HashCodeBuilder()
      builder.append l
      builder.append i
      builder.toHashCode()            
  }
  }
  
  class I {
  String id       
  static mapping = {   
      table "I"       
      id generator:'assigned'
      version: false   
  }   
  static constraints = {
  }
  }
  </code></pre>
  
  <p>bootstrap:</p>
  
  <pre><code>    I ii = new I(id:"I01").save(flush:true)           
      I ii2 = new I(id:"I02").save(flush:true)
  
      L l = new L().save(flush:true);           
      L l2 = new L().save(flush:true);       
  
      LI li = new LI(l:l,i:ii).save(flush:true)       
      LI li2 = new LI(l:l2, i:ii2).save(flush:true)
  </code></pre>
  
  <p>schema:</p>
  
  <p>create table I (id varchar(255) not null, version bigint not null, d varchar(255) not null, primary key (id));
  create table LI (i_id varchar(255) not null, l_id bigint not null, version bigint not null, primary key (i_id, l_id));
  alter table LI add constraint FK97D312CFA foreign key (i_id) references I;
  alter table LI add constraint FK97D328A1A foreign key (l_id) references l;</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Sérgio's solution works but if you have domain I defined like this:</p>
  
  <p>class I {
      String id       </p>
  
  <pre><code>static belongsTo=[A:a] //has only 'string id' column
  
  static mapping = {   
      table "I"       
      id generator:'assigned'
      version: false   
  }   
  static constraints = {
  }
  }
  </code></pre>
  
  <p>Then this won't work:</p>
  
  <pre><code>def c = L.withCriteria {
    lis {
      i {                   
        eq("a.id","A01")                                 
      }
    }
  }
  </code></pre>
  
  <p>if you write just: </p>
  
  <pre><code>def c = L.withCriteria {
    lis {
      i {                   
  
      }
    }
  }
  </code></pre>
  
  <p>this will give the same original error. Something is not correct.</p>