M
M
Medin K2017-02-08 18:11:16
Java
Medin K, 2017-02-08 18:11:16

How to formulate column select query, subquery(count()) with CriteriaQuery?

SELECT
   t.id, t.title,
   (SELECT COUNT(t2.t2_id)
      FROM table2 t2
      WHERE (t2.t2_id = t.id))
FROM table1 t

How to make such a query with CriteriaQuery?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-02-08
@dsv

Not ready to say how to shift to CriteriaQuery, but the query can be rebuilt to:
SELECT
t.id,
t.title,
COUNT(t2.t2_id)
FROM table1 t left join table2 t2 on (t2.t2_id = t.id)
could be like this it will be easier to implement in CriteriaQuery

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question