title: Spring JPA Data: Query ElementCollection
body: <p>I have an entity with an elementCollection:</p>
  <pre><code>@Entity
  class Customer {
    @Column(name = &quot;id&quot;)
    int id;
    String name;
    @ElementCollection
    @CollectionTable(
      joinColumns = @JoinColumn(name = &quot;customer_id&quot;)
    Set&lt;Address&gt; addresses;
  }
  
  @Embeddable
  class Address {
    @Column(name = &quot;address_id&quot;)
    String id;
    String data;
  }
  </code></pre>
  <p>of course the matching data on the db:</p>
  <pre><code>databaseChangeLog:
    - changeSet:
        id: 1
        author: me
        changes:
          - createTable:
              tableName: customer
              columns:
                - column:
                    name: id
                    type: bigint
                    autoIncrement: true
                    constraints:
                      primaryKey: true
                      nullable: false
                - column:
                    name: name
                    type: varchar(255)
          - createTable:
              tableName: address
              columns:
                - column:
                    name: customer_id
                    type: bigint
                     constraints:
                      nullable: false
               - column:
                    name: address_id
                    type: varchar(30)
                - column:
                    name: data
                    type: varchar(255)
          - addForeignKeyConstraint:
              baseTableName: address
              baseColumnNames: customer_id
              referencedTableName: customer
              referencedColumnNames: id
              constraintName: fk_customer_id
          - addUniqueConstraint:
              tableName: address
              name: unique_address_id
              columnNames: address_id
  </code></pre>
  <p>Note: address id is really a String!</p>
  <p>Inserting, and reading works. But my goal is to select <code>Customer</code> by <code>Address.id</code>.</p>
  <p>My goal:</p>
  <pre><code>interface CustomerJpaRepository extends JpaRepository&lt;Customer, Long&gt; {
    XXXX // &lt;-- insert solution here
  }
  </code></pre>
  <p>My ideas for XXXX:</p>
  <ol>
  <li>Using spring data JPA:</li>
  </ol>
  <pre><code>  Customer findByAddressWithId(String addressId);
  </code></pre>
  <p>Of course, this does not work, because the syntax is wrong. But I can't even find a description of the complete syntax for ElementCollections.</p>
  <ol start="2">
  <li>Using a custom query:</li>
  </ol>
  <pre><code>  @Query(value = &quot;select c from Customer c join Address a where a.id = '?1'&quot;)
    Customer findByStreet(String addressId);
  </code></pre>
  <p>This one does not work because <code>a.id</code> can't be found.</p>
  <p>Unfortunately, none of the above work.
  Does anybody have any solution for <code>XXXX</code>?</p>