2
How to get the SQL that is running by JPA when we use a createNamedQuery. I would like to have SQL run to understand where the query problem is below:
Call from the Namequery
EntityManager em = JPAUtil.getEntityManager();
Query query = em.createNamedQuery("buscarTodosItensAnalisePorCpfCnpjEDataMinima");
query.setParameter("cpfCnpj", cpf);
System.out.println("SQL : " + query.toString());
query.setParameter("data", dataPeriodo);
Used namedquery
@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 on 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 >= ?))"))
I need to see SQL with the parameters "?" with the values passed!
Qual JPA preview are using? If you need for more than one, list them.
– Bruno César
Bruno, I’m wearing it
org.eclipse.persistence.jpa.PersistenceProvider
JPA 1.0 pure– Marcelo Gomes