Note that there are some explanatory texts on larger screens.

plurals
  1. POJPA Criteria API - How to add JOIN clause (as general sentence as possible)
    primarykey
    data
    text
    <p>I am trying to construct queries dynamically, and my next target is add JOIN clauses (I don't know how can I use the API).</p> <p>By now, for example, this code work for me :</p> <pre><code>... Class baseClass; ... CriteriaBuilder cb = JpaHandle.get().getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(this.baseClass); Root entity_ = cq.from(this.baseClass); Predicate restrictions = null; ... restrictions = cb.conjunction(); restrictions = cb.and(restrictions, entity_.get("id").in(this.listId)); ... cq.where(restrictions); ... Query qry = JpaHandle.get().createQuery(cq); </code></pre> <p>(Note : JpaHandle is from wicket-JPA implementation)</p> <p><strong>My desire is add JOIN clause (as generical as possible)!</strong> </p> <p>I have the particular annotations in the classes (this.baseClass) </p> <p>For example : </p> <pre><code>@ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "assay_id", nullable = false) </code></pre> <p>So,Is there a way to something like this in standard JPA ? (Note : this don't compile)</p> <p><strong>Here a practical fail aproaches :</strong> </p> <pre><code>... Join&lt;Experiment,Assay&gt; experimentAssays = entity_.join( entity_.get("assay_id") ); </code></pre> <p>Or like that : </p> <pre><code>... CriteriaQuery&lt;Customer&gt; q = cb.createQuery(Customer.class); Root&lt;Customer&gt; c = q.from(Customer.class); SetJoin&lt;Customer, PurchaseOrder&gt; o = c.join(Customer_.orders); </code></pre> <p>For me, if it could be more generical as possible it will be great... : </p> <pre><code>... Join joinClause = entity_join(entity_.get("assay_id"), entity2_.get("id")); </code></pre> <p>Of course, I have the particular annotations in the classes (this.baseClass) </p> <p>Thank you for your time. I'll appreciate all kind of comments!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload