title: Spring Hibernate JPA Specification
body: <p>I have the following Entity: </p>
  
  <pre><code>@Entity
  public class Transaction implements java.io.Serializable {
    private static final long serialVersionUID = 1L;
  
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    protected Long id;
  
    @ElementCollection(fetch = FetchType.EAGER)
    @CollectionTable(name="TRANSACTION_CONFIG", joinColumns=@JoinColumn(name="TRANSACTION_ID"))
    @MapKeyColumn(name = "PROPERTY_KEY")
    @Column(name = "PROPERTY_VALUE")
    protected Map&lt;String, String&gt; properties = new HashMap&lt;String, String&gt;();
  
  
  
    public Transaction() {
      super();
     }
  
    public Long getId() {
      return id;
    }
  
    public void setId(Long id) {
      this.id = id;
    }
  
  
    public Map&lt;String, String&gt; getProperties() {
      return properties;
    }
  
    public void setProperties(Map&lt;String, String&gt; properties) {
      this.properties = properties;
    }
  } 
  </code></pre>
  
  <p>I want to find a transaction by its "properties". For this reason I wrote the following spring Specification class to filter the transaction by its properties. </p>
  
  <pre><code>  public static Specification&lt;Transaction&gt; matches(final Map&lt;String, String&gt; criteria) {
  return new Specification&lt;Transaction&gt;() {
    @Override
    public Predicate toPredicate(Root&lt;Transaction&gt; root, CriteriaQuery&lt;?&gt; query,
        CriteriaBuilder builder) {
      List&lt;Predicate&gt; predicates = new ArrayList&lt;Predicate&gt;();
      Path&lt;Map&lt;String, String&gt;&gt; propertiesRoot = root.join("properties");
      for (String key : criteria.keySet()) {
        Predicate p = builder.and(propertiesRoot.in(key), propertiesRoot.in(criteria.get(key)));
        predicates.add(p);
      }
      return builder.isTrue(propertiesRoot.in(criteria));
    }
  };
  </code></pre>
  
  <p>}</p>
  
  <p>But this doesn't seem to return anything. Any idea about what I am doing wrong ? </p>