title: Use CriteriaBuilder on embedded object
body: <p>I am trying to use <code>@Embeddable</code> with <code>CriteriaBuilder</code> to filter results of a parent <code>Entity</code> based on the embedded property. I use Eclipse Link to generate the Metadata classes.</p>
  <p>Here is the embedded class/entity:</p>
  <pre><code>@Embeddable
  public class Stamp implements Serializable {
  
     @Basic()
     @Column(name = &quot;stamp_year&quot;, nullable = false)
     private int year;
  </code></pre>
  <p>The parent class has the <code>Stamp</code> as a member:</p>
  <pre><code>@Entity(name = &quot;Message&quot;)
  public class Message implements Serializable {
  
     @Embedded
     private Stamp stamp = new Stamp();
  </code></pre>
  <p>Now this code should use the <code>Message</code> class and filter results based on the embedded class property year:</p>
  <pre><code>    CriteriaBuilder cb = em.getCriteriaBuilder();
      CriteriaQuery&lt;Message&gt; cq = cb.createQuery(Message.class);
      Root&lt;Message&gt; root = cq.from(Message.class);
      Predicate p = cb.conjunction();
      p = ??????
      cq.where(p);
      TypedQuery&lt;Message&gt; tq = em.createQuery(cq);
      List&lt;Message&gt; messages = tq.getResultList();
  </code></pre>
  <p>On line 5 how do I get to the Message-&gt;Stamp-&gt;Year element of the query?</p>
  <p>here are the generated metamodel classes:</p>
  <pre><code>@StaticMetamodel(Message.class)
  public class Message_ { 
  
      public static volatile SingularAttribute&lt;Message, Stamp&gt; stamp;
  </code></pre>
  <p>and:</p>
  <pre><code>@StaticMetamodel(Stamp.class)
  public class Stamp_ { 
  
     public static volatile SingularAttribute&lt;Stamp, Integer&gt; year;
  </code></pre>
  <p>Note: I removed all irrelevant information for code clarity but the full code is available on GitHub:
  <a href="http://github.com/gadieichhorn/prototype-jpa" rel="nofollow noreferrer">prototype</a></p>