How to get the SQL that is being executed by JPA when we use a createNamedQuery. I would like to have SQL executed to understand where the query problem is:
Calling NameQuery
EntityManager em = JPAUtil.getEntityManager();
Query query = em.createNamedQuery("buscarTodosItensAnalisePorCpfCnpjEDataMinima");
query.setParameter("cpfCnpj", cpf);
System.out.println("SQL : " + query.toString());
query.setParameter("data", dataPeriodo);
NamedQuery used
@NamedQueries({
@NamedQuery(name="buscarTodosItensAnalisePorCpfCnpj",query="SELECT i FROM ItemAnalise i WHERE i.cpfCnpj = :cpfCnpj"),
@NamedQuery(name="buscarTodosItensAnalisePorCpfCnpjEDataMinima",query="SELECT i FROM ItemAnalise i WHERE i.cpfCnpj = :cpfCnpj AND i.dataRegistro >= :data")
})
I'm using:
System.out.println("SQL : " + query.toString());
The result in the console is:
SQL : EJBQueryImpl(ReadAllQuery(name="buscarTodosItensAnalisePorCpfCnpjEDataMinima" referenceClass=ItemAnalise sql="SELECT id, atividade_id, cpfcnpj, data_atualizacao, data_registro, login, situacao FROM item_analise WHERE ((cpfcnpj = ?) AND (data_registro >= ?))"))
Do I need to see SQL with the "?" with past values!