Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This one compiles without errors. However, I did not try to run it, so you may get some exceptions (e.g. from <code>queryRoot.asInstanceOf[Root[T]]</code>, I have a little bit bad feeling about it):</p> <pre><code> def findByAttributes(attributes:AttributeValuePair[_]*):ArrayList[T] = { val cq = cb.createQuery(m.erasure) val queryRoot = cq.from(m.erasure) var criteria = cb.conjunction for (pair &lt;- attributes) { criteria = pred(pair, cb, queryRoot.asInstanceOf[Root[T]]) } cq.where(Seq(criteria):_*) val results = em.createQuery(cq).getResultList results.asInstanceOf[ArrayList[T]] } def pred[A](pair: AttributeValuePair[A], cb: CriteriaBuilder, queryRoot: Root[T]): Predicate = cb.and(cb.equal(queryRoot.get(pair._1),pair._2)) </code></pre> <p>BTW in <code>SuperDAO.findByAttributes</code> the parentheses/params of <code>cb.equal</code> seems to be a bit mixed up. It looks OK in the other method.</p> <p>About the <code>_$1</code> type: I think when you say <code>SingularAttribute[T,_]</code> it will be a so called existential type. It is a shorthand for <code>SingularAttribute[T,X] forSome { type X }</code>. So the <code>_</code> means that we don't really know what X is, but for sure there is a fixed type there. As you can have several existential types the compiler just calls them <code>_$1</code>, <code>_$2</code> and so on. They are synthetically created names instead of <code>X</code>-es.<br> Existential types are used mostly when you use Java generics with wildcard or raw types. In these cases some tricks (like introducing an extra method with it's own type param) may be needed for proper type checking.</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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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