Hibernate console configuration and usage

Hibernate console configuration and usage. Execute HQL, JPQL and Hibernate Criteria query. How to graphically see entities mapping. Presented on MySQL database.

When you create a Hibernate project, you will also create a Hibernate console. It is a tool for testing your Hibernate configuration and executing HQL and criteria queries. Btw this tool works also with JPA projects based on EclipseLink, TopLink and other JPA implementations. And you can execute not only HQL, but also JPQL.

In hello world projects basic configuration usually works fine, but once you start modifying your configuration, your Hibernate console may not work because by default it depends on connection defined in your project configuration. To change that choose "Edit Configuration", select which type of project you use, I use JPA, choose Hibernate version and switch Database connection to your defined database connection in Eclipse.

If you have more persistence units in persistence.xml file, choose which one will be used. Depending on your version of Hibernate you may also need to choose Database dialect.

You can open HQL editor and inside you can write HQL or JPQL query. Next you can run this query. Hibernate Dynamic SQL Preview shows you SQL query which will be executed in your database. You can also add dynamic query parameters.

You can also test your Hibernate Criteria Query using Hibernate Criteria Editor and you can also graphically see mapping between your entities and tables in database.