sebastiandaschner blog
Log JPA schema creation with Hibernate
wednesday, april 15, 2015The JPA provider can create the database schema from the Entity beans.
This behaviour is configured in the persistence.xml
file.
You can display the SQL scripts which were used to generate the database schema with Hibernate.
Therefore you configure the hibernate.show_sql
property to true
and the hibernate.hbm2ddl.auto
property to create
in your persistence.xml
file:
<properties>
...
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create" />
</properties>
Also set the log level for the org.hibernate.tool.hbm2ddl
logger to DEBUG
.
The create SQL statements will appear in the log:
org.hibernate.tool.hbm2ddl.SchemaExport execute Hibernate: create table customers (id bigint not null, ... ... org.hibernate.tool.hbm2ddl.SchemaExport execute
Found the post useful? Subscribe to my newsletter for more free content, tips and tricks on IT & Java: