Thursday, March 16, 2017

Hibernate is slow at startup with Running schema validator

Leave a Comment

I've been running Spring-Boot with JPA and a Postgres Database. Depending on my network environment the starting phase is blocking for more than 15 sec on :

INFO  o.h.tool.hbm2ddl.SchemaValidator - HHH000229: Running schema validator 

The strange thing is that my Database is local. Any idea ?

    spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false     spring.jpa.hibernate.ddl-auto= validate     spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect     spring.datasource.driverClassName=org.postgresql.Driver     spring.datasource.url=jdbc:postgresql://localhost:5432/cine 

2 Answers

Answers 1

In any problem like this get hold of a profiler (Yourkit is excellent) and profile your app at startup to see what's taking the time. Yourkit not only will show you hotspots (methods taking disproportionately longer times) but will also show you any database queries and how long they took.

Make sure you start profiling in full trace mode (this can be configured in your IDE e.g. in IntelliJ on the startup tab of your run configuration).

Answers 2

The schema validator is just slow. We ended up adding this line to our spring configuration file for our "dev" environment profile (application-dev.properties)

spring.jpa.hibernate.ddl-auto=none 

This is a bit risky, since the consistency between the database and JPA entities are not verified. But, we have both Test- and QA environments that would pick up any problems.

This fix did cut my startup process by about 20 seconds.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment