Subquery in the select clause with JPA Criteria

Asked

Viewed 831 times

2

I was searching how to do a subquery in the select clause with Criteria of a select of this type:

SELECT tabela1.*,tabela2.*,
(SELECT MAX(tabela5.AtrDatatabela5) 
FROM .Tabela3 AS tabela3 
    INNER JOIN Tabela4 AS tabela4 ON tabela4.AtrIdTabela4 = tabela3.AtrIdTabela4
    LEFT outer JOIN CraMar AS tabela5 ON tabela5.AtrIdTabela4 = tabela4.AtrIdTabela4
WHERE  tabela4.AtrIdTipoTabela4 = 1
    AND tabela3.AtrIdTabela2 = tabela2.atridTabela2 
    AND tabela3.AtrDataDevolucao IS NULL
    AND tabela5.AtrDataTabela5 between 'Mar 29 2016 00:00' and 'Mar 29 2016 23:59'
    AND tabela5.AtrCodigoTabela5 IN ('E', 'S')) as utlimaTabela5
FROM Tabela1 AS tabela1...

1 answer

0


JPA 2.0 can’t stand it sub-query in the SELECT clause. See if you can change your original SQL to get the same result without this sub-query. From there, it is easier to make an equivalent query with Criteria.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.