title: LIKE clause on Map key and value - querydsl
body: <p>Is there a way to convert given query from <code>@Query</code> annotation to Query DSL?<br/>
  The idea is to search for countries by few first characters of name.<br/>
  While using Hibernate 5.5.6.Final, this query was fine, but today I tried Hibernate 6.0.0.Alpha9 and it does not like my query at all.</p>
  <pre><code>@Query(
      &quot;SELECT DISTINCT c &quot; +
      &quot;FROM Country c &quot; +
      &quot;LEFT JOIN FETCH c.localizations loc &quot; +
      &quot;WHERE &quot; +
          &quot;KEY( loc ) LIKE 'NAME%' &quot; +
          &quot;AND &quot; +
         &quot;LOWER( loc ) LIKE LOWER( :name ) &quot;
  )
  List&lt;Country&gt; findByFirstChars( @Param(value = &quot;name&quot;) String name );
  </code></pre>
  <p>Country entity:</p>
  <pre><code>@Getter @Setter
  class Country {
      // map entry key can be &quot;NAME1&quot;, &quot;NAME2&quot;, &quot;NOTE1&quot;, &quot;NOTE2&quot;...
      // while map entry value is country name or some note
      private Map&lt;String, String&gt; localizations;
      ...more properties
  }
  </code></pre>
  <p>Q classess are generated by Maven APT plugin, querydsl-apt and querydsl-jpa.</p>
  <p>This is what I want:</p>
  <pre><code>List&lt;Country&gt; findByFirstChars( String name ) {
      return new JPAQueryFactory( entityManager )
                  .selectFrom( QCountry.country )
                  .where( ??? )
                  .fetch();
  }
  </code></pre>
  <h1>EDIT: Another try which failed</h1>
  <pre><code>List&lt;Country&gt; findByFirstChars(String name) {
      QCountry country = QCountry.country;
  
      BooleanExpression whereClause1 =
          Expressions.stringTemplate(&quot;KEY({0})&quot;,
              country.localizations).like(KEY_PREFIX + &quot;%&quot;);
  
      BooleanExpression whereClause2 =
          Expressions.stringTemplate(&quot;LOWER({0})&quot;,
              country.localizations).likeIgnoreCase(name);
  
      return 
          new JPAQueryFactory(this.entityManager)
              .selectFrom(country)
              .distinct()
              .leftJoin(country.localizations).fetchJoin()
              .where(                 
                  whereClause1.and(whereClause2)
              )
              .fetch();
  }
  </code></pre>
  <p>It generates almost the same HQL as original one:</p>
  <pre><code>select distinct country
  from Country country
    left join fetch country.localizations.data
  where KEY( country.localizations.data ) like ?1 escape '!'
      and lower(LOWER( country.localizations.data )) like ?2
  </code></pre>
  <p>but I get an error: <b><i>Parameter value [cro] did not match expected type [java.util.Map (n/a)]</i></b><br/>
  <br/></p>
  <p>If I use <code>VALUE()</code> in <code>whereClause2</code> the HQL is:</p>
  <pre><code>select distinct country
  from Country country
    left join fetch country.localizations.data
  where KEY( country.localizations.data ) like ?1 escape '!'
     and lower(VALUE( country.localizations.data )) like ?2 
  </code></pre>
  <p>and also I get an error: <b><i>SQL Error: 1242, SQLState: 21000 - Subquery returns more than 1 row</i></b></p>