Hibernate startup very slow
Startup slow may be caused by this config:
<property name="hbm2ddl.auto">update</property>
This config means when hibernate start, check if the entity matching with ddl, and do action such as 'create','update'. This will cost too much time.
So the solution is comment this config. Then hibernate will start without validate.
For Postgres, add in application config:
spring.jpa.database-platform = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
First line is necessary if not determine Dialect
Results
Before:
09:10:19.637 [main] INFO o.h.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
09:14:17.159 [main] INFO org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL9Dialect
~4 minutes
After:
09:40:10.930 [main] INFO o.h.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
09:40:11.043 [main] INFO org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
~1 minute
See Hibernate Slow to Acquire Postgres Connection
hibernate.temp.use_jdbc_metadata_defaults=false
To avoid meta-data reload during SessionFactory creation.