title: EclipseLink JPA CriteriaBuilder generated invalid SQL Syntax
body: <p>I have two objects, both defined as entities, one containing the other as follows:</p>
  
  <pre><code>@Entity
  public class TestC 
  {
      @Id @GeneratedValue
      private Integer id;
      @ManyToOne (cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
      TestD d;
  } 
  
  @Entity
  public class TestD 
  {
      @Id @GeneratedValue
      private Integer id;
      String moo;
  }    
  </code></pre>
  
  <p>The entities are persisted:</p>
  
  <pre><code>TestC c2 = new TestC();
  TestD d2 = new TestD();
  d2.moo = "d2";
  c2.d = d2;
  em.getTransaction().begin();
  em.persist(d2);
  em.persist(c2);
  em.getTransaction().commit();
  </code></pre>
  
  <p>I am trying to query for TestC objects with an instance of TestD:</p>
  
  <pre><code>CriteriaBuilder builder = em.getCriteriaBuilder();
  CriteriaQuery&lt;TestC&gt; query = builder.createQuery(TestC.class);
  Root&lt;TestC&gt; from = query.from(TestC.class);
  
  ParameterExpression&lt;TestD&gt; pe = builder.parameter(TestD.class);
  
  query.where(builder.equal(pe, from.&lt;TestD&gt;get("d")));
  
  TestC found = em.createQuery(query)
      .setParameter(pe, d2)
      .getSingleResult();
  </code></pre>
  
  <p>But EclipseLink kicks out the following error when running the query (note the SQL is invalid near "(? = )", there is no column name for the TestD object):</p>
  
  <pre><code>Exception in thread "main" Local Exception Stack: 
  Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
  Internal Exception: java.sql.SQLException: Invalid argument value: java.io.NotSerializableException
  Error Code: 0
  Call: SELECT t1.ID, t1.D_ID FROM TESTD t0, TESTC t1 WHERE ((? = ) AND (t0.ID = t1.D_ID))
  bind =&gt; [1 parameter bound]
  Query: ReadAllQuery(referenceClass=TestC sql="SELECT t1.ID, t1.D_ID FROM TESTD t0, TESTC t1 WHERE ((? = ) AND (t0.ID = t1.D_ID))")
  </code></pre>
  
  <p>Am I building the query wrong?</p>
  
  <p>Thanks for any help!</p>