title: Query @ElementCollection JPA
body: <p>I have an <code>Entity</code> <code>Transaction</code> as following : </p>
  
  <pre><code>@Entity
  class Transaction extends AbstractEntity&lt;Long&gt;{
          private static final long serialVersionUID = 7222139865127600245L;
          //other attributes
  
      @ElementCollection(fetch = FetchType.EAGER, targetClass = java.lang.String.class)
      @CollectionTable(name = "transaction_properties", joinColumns = @JoinColumn(name = "p_id"))
      @MapKeyColumn(name = "propertyKey")
      @Column(name = "propertyValue")
      private Map&lt;String, String&gt; properties;
  
      //getters and setters
  }
  </code></pre>
  
  <p>So, my Database <code>Table</code> for <code>transaction_properties</code> is </p>
  
  <pre><code>mysql&gt; desc transaction_properties;
  +---------------+--------------+------+-----+---------+-------+
  | Field         | Type         | Null | Key | Default | Extra |
  +---------------+--------------+------+-----+---------+-------+
  | p_id          | bigint(20)   | NO   | PRI |         |       |
  | propertyValue | varchar(255) | YES  |     | NULL    |       |
  | propertyKey   | varchar(255) | NO   | PRI |         |       |
  +---------------+--------------+------+-----+---------+-------+
  3 rows in set (0.00 sec)
  </code></pre>
  
  <p>Now, I want to search entity <code>Transaction</code> with key and value.</p>
  
  <pre><code>    Path&lt;Map&lt;String, String&gt;&gt; propertiesPath = root.get("properties");
      Path&lt;String&gt; propertyKeyPath = propertiesPath.&lt;String&gt; get("propertyKey"); //where m getting error
      Path&lt;String&gt; propertyValuePath = propertyKeyPath.&lt;String&gt; get("propertyValue");
      p = cb.and(p, cb.and(cb.like(propertyKeyPath, "%" + searchTrxnKey + "%"), cb.like(propertyValuePath, "%" + searchTrxnValue + "%")));
  </code></pre>
  
  <p>But am getting error for <code>Path&lt;String&gt; propertyKeyPath = propertiesPath.&lt;String&gt; get("propertyKey");</code> as following : </p>
  
  <pre><code>[...] threw an unexpected exception: org.springframework.dao.InvalidDataAccessApiUsageException: Illegal attempt to dereference path source [null]; nested exception is java.lang.IllegalArgumentException: Illegal attempt to dereference path source [null]
  </code></pre>
  
  <p>One of the reference I went through was : <a href="http://www.petrikainulainen.net/programming/spring-framework/spring-data-jpa-tutorial-part-four-jpa-criteria-queries/" rel="noreferrer">Spring Data JPA Tutorial Part Four: JPA Criteria Queries</a> but no luck for me.</p>