title: JPA/ JPQL: How to use member-of with an hash-map
body: <p>I have problem using the member-of Statement. The problem I think is, that I made a mistake with the elements --> parameter.get("" i + anlass) but I don't know how to do it right. 
  Are there any other possibilities to ask if a certain element is an <code>@ManyToMany</code> List from another Object? </p>
  
  <p>Here's my Code: </p>
  
  <pre><code>   /*My Beans: 
      @Entity
      public class Rezept implements Serializable {
      ...........
      @ManyToMany(mappedBy="rezepten", cascade = {CascadeType.PERSIST})
       List&lt;Allergie&gt; allergien = new ArrayList&lt;&gt;();
  
      @ManyToMany(mappedBy="rezepten", cascade = {CascadeType.PERSIST})
       List&lt;Anlass&gt; anlässe = new ArrayList&lt;&gt;();
  
      @ManyToMany(mappedBy="rezepten", cascade = {CascadeType.PERSIST})
       List&lt;Grundzutat&gt; grundzutaten = new ArrayList&lt;&gt;();*/
  
  
  
  //The method is in the RezeptBean
   public List&lt;Rezept&gt; searchByFilters(List&lt;Anlass&gt; anlaesse, List&lt;Grundzutat&gt; grundzutaten, List&lt;Allergie&gt; allergien) {
      // WHERE-Bedingungen für die Filteroptionen zusammenbauen
      String select = "SELECT r FROM Rezept r";
      String where = "";
  
      Map&lt;String, Object&gt; parameters = new HashMap&lt;&gt;();
      int i = 0;
  
      for (Anlass anlass : anlaesse) {
          i++;
          parameters.put("" + i, anlass);
  
          if (!where.isEmpty()) {
              where += " AND ";
          }
          //Here I want to see if the element parameters.get("" + i) is member 
           of r.anlässe
          where += ":" + parameters.get("" + i) + " MEMBER OF r.anlässe";
      }
  
      for (Grundzutat grundzutat : grundzutaten) {
          i++;
          parameters.put("" + i, grundzutat);
  
          if (!where.isEmpty()) {
              where += " AND ";
          }
  
          where += ":" + parameters.get("" + i) + " MEMBER OF r.grundzutaten";
      }
  
      for (Allergie allergie : allergien) {
          i++;
          parameters.put("" + i, allergie);
  
          if (!where.isEmpty()) {
              where += " AND ";
          }
  
          where += ":" + parameters.get("" + i) + " MEMBER OF r.allergien";
      }
  
      // Finalen SELECT-String zusammenbauen und Suche ausführen
      if (!where.isEmpty()) {
          select += " WHERE " + where;
      }
  
      Query query = em.createQuery(select);
  
      for (String key : parameters.keySet()) {
          query.setParameter(key, parameters.get(key));
      }
  
      return query.getResultList();
  }
  
  
  }
  </code></pre>
  
  <p>This is the log file: </p>
  
  <pre><code>    Warnung:   A system exception occurred during an invocation on EJB RezeptBean, method: public java.util.List rezept.ejb.RezeptBean.searchByFilters(java.util.List,java.util.List,java.util.List)
  Warnung:   javax.ejb.EJBException
      at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:752)
      at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:702)
      at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:507)
      at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4566)
      at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2074)
      at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2044)
      at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:220)
      at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
      at com.sun.proxy.$Proxy1243.searchByFilters(Unknown Source)
      at rezept.ejb.__EJB31_Generated__RezeptBean__Intf____Bean__.searchByFilters(Unknown Source)
      at rezept.web.SuchServlet.doGet(SuchServlet.java:125)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
      at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
      at rezept.web.JavaFilter.doFilter(JavaFilter.java:48)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
      at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
      at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
      at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
      at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
      at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
      at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
      at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
      at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
      at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
  Exception Description: Syntax error parsing [SELECT r FROM Rezept r WHERE :rezept.jpa.Anlass@2c9e9a75 MEMBER OF r.anlässe AND :rezept.jpa.Grundzutat@3c634785 MEMBER OF r.grundzutaten AND :rezept.jpa.Grundzutat@3c30782 MEMBER OF r.grundzutaten AND :rezept.jpa.Allergie@4f608eda MEMBER OF r.allergien AND :rezept.jpa.Allergie@1482f49f MEMBER OF r.allergien]. 
  [29, 56] The named input parameter ''{0}'' is not following the rules for a Java identifier.
  [81, 112] The named input parameter ''{0}'' is not following the rules for a Java identifier.
  [142, 172] The named input parameter ''{0}'' is not following the rules for a Java identifier.
  [202, 231] The named input parameter ''{0}'' is not following the rules for a Java identifier.
  [258, 287] The named input parameter ''{0}'' is not following the rules for a Java identifier.
      at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1616)
  ....................
  </code></pre>
  
  <p>Has somebody an idea what I can do different? </p>