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 caseshow_sql
is on, settingtrue
forformat_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 tablecreate-drop
- tables will be created on startup ofSessionFactory
and deleted when closing theSessionFactory
create
- removes old data from the database and creates tablesupdate
- 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