title: How to create custom query for CollectionOfElements
body: <p>I have problems creating a custom query.</p>
  
  <p>This is what entities:</p>
  
  <pre><code>@Entity
  public class ApplicationProcess {
  
      @CollectionOfElements
      private Set&lt;Template&gt; defaultTemplates;
      //more fields
  }
  </code></pre>
  
  <p>And Template.java</p>
  
  <pre><code>@Embeddable
  @EqualsAndHashCode(exclude={"used"})
  public class Template implements Comparable&lt;Template&gt; {
  
   @Setter private ApplicationProcess applicationProcess;
   @Setter private Boolean used = Boolean.valueOf(false);
  
   public Template() {
   }
  
   @Parent
   public ApplicationProcess getApplicationProcess() {
     return applicationProcess;
   }
  
   @Column(nullable = false)
   @NotNull
   public String getName() {
     return name;
   }
  
   @Column(nullable = true)
   public Boolean isUsed() {
     return used;
   }
  
   public int compareTo(Template o) {
     return getName().compareTo(o.getName());
   }
  }
  </code></pre>
  
  <p>I want to create a update statement. I have tried these two:</p>
  
  <pre><code>int v = entityManager.createQuery("update ApplicationProcess_defaultTemplates t set t.used = true " + "WHERE t.applicationProcess.id=:apId").setParameter("apId", ap.getId())
     .executeUpdate();
  </code></pre>
  
  <p><code>ApplicationProcess_defaultTemplates is not mapped [update ApplicationProcess_defaultTemplates t set t.used = true WHERE t.applicationProcess.id=:apId]</code></p>
  
  <p>And I have tried </p>
  
  <pre><code> int v = entityManager.createQuery("update Template t set t.used = true " + "WHERE t.applicationProcess.id=:apId").setParameter("apId", ap.getId())
     .executeUpdate();
  </code></pre>
  
  <p>With the same error:</p>
  
  <p><code>Template is not mapped [update Template t set t.used = true WHERE t.applicationProcess.id=:apId]</code></p>
  
  <p>Any ideas?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I fixed it by creating native query</p>
  
  <pre><code>int v = entityManager.createNativeQuery("update ApplicationProcess_defaultTemplates t set t.used=true where t.ApplicationProcess_id=:apId").setParameter("apId", ap.getId()).executeUpdate();
  </code></pre>