Skip to content

Useful configuration properties

As we showed here, Hibernate requires a configuration file in which, in addition to information on how to connect to the database, we can define additional properties. In this section we will describe some of them.

  • show_sql - if we want HQL queries executed by Hibernate to be logged on the console screen, we should set the value of this property totrue
  • format_sql - in case show_sql is on, setting true for format_sql will improve readability of long and complicated queries
  • hbm2ddl.auto - allows you to define whether and how Hibernate should generate (i.e. create) tables based on the entity definition. Several possible values ​​are, e.g .:

    • none - Hibernate will not generate the database table
    • create-drop - tables will be created on startup of SessionFactory and deleted when closing the SessionFactory
    • create - removes old data from the database and creates tables
    • update - updates tables (if required or creates if they do not exist)
    • validate - checks if the database tables match the entity definitions
  • dialect - indicates the class that defines the dialect of a specific database implementation, e.g.:

    • org.hibernate.dialect.MySQL8Dialect
    • org.hibernate.dialect.PostgreSQLDialect