title: Incorrect JPQL query formed when joining tables
body: <p>Let's say I have 2 entities: <strong>Application</strong> and <strong>Organization</strong>. They are many-to-many related</p>
  
  <p><strong>Organization:</strong></p>
  
  <pre><code>@Entity
  @Table(name = "organizations")
  public class Organization
  {
  
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "organizationIdGenerator")
      private long id;  // primary key
  
      @AttributeOverride(name = "id", column = @Column(name = "organization_id", unique = true, updatable = false))
      @Embedded
      private OrganizationId organizationId;
  
      @AttributeOverride(name = "id", column = @Column(name = "application_id"))
      @CollectionTable(name = "organization_applications")
      @ElementCollection
      private Set&lt;ApplicationId&gt; applications = new HashSet&lt;&gt;();  // there is no explicit @Many-to-many connection between applications and organizations
  
      private String name;
  
      // other data
  }
  </code></pre>
  
  <p><strong>Application:</strong></p>
  
  <pre><code>@Entity
  @Table(name = "applications")
  public class Application
  {
  
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "applicationIdGenerator")
      private long id; // primary key
  
      @AttributeOverride(name = "id", column = @Column(name = "application_id", unique = true, updatable = false))
      @Embedded
      private ApplicationId applicationId;
  
      private String label;
  
      // other data 
  }
  </code></pre>
  
  <p>As they are many-to-many related, in relational database I have the following tables:</p>
  
  <ul>
  <li><code>organizations</code></li>
  <li><code>applications</code></li>
  <li><code>organization_applications</code></li>
  </ul>
  
  <p>table <code>organization_applications</code> is created with the following liquibase-migration:</p>
  
  <pre><code>&lt;createTable tableName="organization_applications"&gt;
    &lt;column name="organization_id" type="bigint"&gt;
      &lt;constraints nullable="false" foreignKeyName="organization_application_organization_id_fk"
                   referencedTableName="organizations" referencedColumnNames="id"/&gt;
    &lt;/column&gt;
    &lt;column name="application_id" type="varchar(50)"&gt;
      &lt;constraints nullable="false"/&gt;
    &lt;/column&gt;
  &lt;/createTable&gt;
  </code></pre>
  
  <hr>
  
  <p><em>What I want to do is get Applications (<code>List&lt;Application&gt;</code>) for particular Organization in one query</em></p>
  
  <hr>
  
  <p>I can do it by getting applicationIds of particular organization (lets say with organizationId = 1) and join them with <code>applications</code> with a query like:</p>
  
  <pre><code>select apps.application_id, apps.label 
      from organization_applications org_apps
      join applications apps 
          on (apps.application_id = org_apps.application_id and org_apps.organization_id = 1)
  </code></pre>
  
  <p>But when I try to accomplish this with JPQL query like this:</p>
  
  <pre><code>SELECT new List(o.applications) FROM Organization o WHERE o.organizationId.id = 1
  </code></pre>
  
  <p>I get the following query and then and exception:</p>
  
  <pre><code>Hibernate: 
      /* SELECT
          new List(o.applications) 
      FROM
          Organization o 
      WHERE
          o.organizationId.id = :org_id */ select
              . as col_0_0_          // &lt;-- problem here. why is there just a dot?
          from
              organizations organizati0_ 
          inner join
              organization_applications applicatio1_ 
                  on organizati0_.id=applicatio1_.organization_id 
          where
              organizati0_.organization_id=?
  
  SqlExceptionHelper   : SQL Error: 20000, SQLState: 42X01
  SqlExceptionHelper   : Syntax error: Encountered "." at line 1, column 102.
  </code></pre>
  
  <p>Seems that in a relation like this where entities are related by custom id fields (applicationId, organiationId) hibernate cannot create query.</p>
  
  <p>Any idea how can I accomplish this?</p>
  
  <p>Thanks in advance!</p>
  
  <hr>
  
  <p>UPD:</p>
  
  <p><strong>ApplicationId</strong> holds some validation and looks like this:</p>
  
  <pre><code>public class ApplicationId
  {
      private String id;
  
      // constructor and getters
  }
  </code></pre>
  
  <p><strong>OrganizationId</strong> looks exactly the same</p>