Group_concat in JPQL

1

I created the following query:

SELECT 
o.codigoChamado,
o.codigoOrcamento,
group_concat(o.conteudoOrcamento),
o.observacaoOrcamento
FROM 
Orcamentos  as o
group by
o.codigoChamado,
o.codigoOrcamento,
o.observacaoOrcamento
order by 
o.codigoOrcamento

When executed directly on the database, I get the expected result normally, however this query needs to be executed via JPQL and group_concat is not native to JPQL, there is something I can replace group_concat but still get the same return?

    
asked by anonymous 10.10.2018 / 16:29

1 answer

0

You can use FUNCTION of JPQL to call native functions or functions created in the database.

To call it, you must supply the name of the function in the first parameter and in the other parameters you fill it with the parameters that go to the function of the database.

In your example, it would look like:

FUNCTION(group_concat, o.conteudoOrcamento)

Your entire query looks like this:

String jpql = "SELECT o.codigoChamado, o.codigoOrcamento, FUNCTION(group_concat, 
    o.conteudoOrcamento), o.observacaoOrcamento FROM  Orcamentos o
    group by o.codigoChamado, o.codigoOrcamento, o.observacaoOrcamento order by o.codigoOrcamento"
Query query = em.createQuery(jpql);
    
21.12.2018 / 13:47