How can I see the SQL query using Hibernate Tools in Eclipse?

With Hibernate Tools installed in Eclipse, how can I view the requested SQL query from JPA query language? (I am using Hibernate as my JPA implementation)

My Java DAO class looks something like this:

public List<Person> findById(int id)
{
    return entityManager.find(Person.class, id);
}
public List<Person> find(String name)
{
    Query q = entityManager.createQuery("SELECT p FROM Person p WHERE name=?");
    q.setParameter(1, name);
    return q.getResultList();
}

      

I want to see what happens to the SQL query. I've heard that Hibernate Tools has some support.

+1


source to share


2 answers


To see the SQL query, you can simply tune hibernate.show_sql = true in your hibernate.cfg.xml file. Then you should see prompts in the console window while the application is running.



This is a property of the hibernate environment when Tools provides you with an HQL editor, so you can test your queries before putting them into code.

+4


source


The Hibernate Tools have support for this:

1) Use the HQL editor (you can get the query there automatically by placing the cursor in the query and press Ctrl + 1 and then it will be able to open in the HQL editor).



2) Make sure you open / render the dynamic SQL view, then it will show what SQL Hibernate will generate from your HQL.

3) Done;)

+3


source







All Articles