Passando uma lista como parametro, mas retornando o erro: The left parenthesis is missing from

3 respostas
J

A ideia é receber uma lista que contenha os nomes, e retornar uma lista que não tenha esses nome que está nessa lista recebida.

Então, o código é esse:

public ArrayList<String> findSelectedList(List<String> lista) {
       
        ArrayList<String> layoutsSelecionados = new ArrayList<String>();
         EntityManager em = getEntityManager();
        String sql=  "select u.nome from Layoutsos u where u.nome not in = " + lista + "";
      
        
         layoutsSelecionados = (ArrayList<String>) em.createQuery(sql).getResultList();
        em.getTransaction().commit();
        
        return layoutsSelecionados ;
        
    }

E esses erros aparecem:

[code]Exception Description: Syntax error parsing [select u.name from Layoutsos u where u.name not in = [Banner, Cartaz, Cartaz]]. 
[50, 50] The left parenthesis is missing from the IN expression.
[77, 77] The right parenthesis is missing from the IN expression.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1605)

3 Respostas

J

Resolvi mudando a query: "select (u.nome)from Layoutsos u where u.nome not in:=("+lista+")";

mas esse erro apareceu:

Essa é a linha q ele mostra o erro:

J

miss click

V

Só ví agora.
Faz assim
"select u.nome from Layoutsos u where u.nome not in:=("+lista+")";

mas pense bem: Se o tamanho da sua lista crescer muito esse modo de construir sua SQL gera um custo muito alto. Há outros meios de fazer essa SQL ser menos custosa para o BD procure pelo “exists”.

Criado 16 de novembro de 2015
Ultima resposta 4 de ago. de 2016
Respostas 3
Participantes 2