title: JPA @ElementCollection how can I query?
body: <p>I am using Spring JPA and in order to ad a List of String to my Entity I am using @ElementCollection as below.</p>
  
  <pre><code>@ElementCollection
  private Map&lt;Integer, String&gt; categories;
  </code></pre>
  
  <p>When I use this it generates a table called <code>subscription_categories</code> this contains the following columns <code>subscription(varchar), catergories(varchar) and caterogies_key (int)</code></p>
  
  <p>If I use my SQL tool on my desktop I can query this table fine with the following</p>
  
  <pre><code>select `subscription_categories`.`subscription` from `subscription_categories` where `subscription_categories`.`categories`='TESTING';
  </code></pre>
  
  <p>However, when I attempt to use this in Spring Data it fails with a "... not mapped" error</p>
  
  <p>Here are a few attempts below:</p>
  
  <pre><code>@Query("select s.subscription from subscription_categories s where s.categories = ?1")
      List&lt;Subscription&gt; findUsernameByCategory(String category);
  
  
  
  @Query("select s.subscription from categories s where s.categories = ?1")
      List&lt;Subscription&gt; findUsernameByCategory(String category);
  </code></pre>
  
  <p>Both return the same error.</p>
  
  <blockquote>
    <p>Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException:
    categories is not mapped</p>
  </blockquote>
  
  <p><strong>My question is this:</strong> </p>
  
  <p><strong>How can I query the table created by the @ElementCollection?</strong></p>