QueryDSL: Query by composite primary key
<p>I have an entity <code>Parte</code> with a composite primary key. These are the columns: </p>

<ul>
<li><code>codabast</code></li>
<li><code>codejerc</code></li>
<li><code>codparte</code></li>
</ul>

<p>I have annotated my entity with <code>@IdClass(PartePK.class)</code>. Now, to perform a query by primary key, I do this:</p>

<pre><code>JPAQuery query = new JPAQuery(entityManager);

query.from(qParte).where(qParte.codabast.eq(myCodAbast)
    .and(qParte.codejerc.eq(myCodEjerc)
    .and(qParte.codparte.eq(myCodParte))));

Parte p = query.singleResult(qParte);
</code></pre>

<p>Is it needed to do it field by field? Or does exist a way to query by primary key?</p>

<p>I would like something like this:</p>

<pre><code>PartePK primaryKey = new PartePK(3, 4, 6);
query.from(qParte).byId(primaryKey);
</code></pre>

<p>Thanks in advance.</p>