For some reason, the startup of my hibernate application is unbarrably slow. (up to 2 min) I have been thinking that the c3p0 configuration is plain wrong (related question)
If it is abnormally slow then you probably have a lock in your application, or some resource blocks. In any case download VisualVM (JDK includes jconsole, dumbed down version of it) and check what your threads are doing, where they are stuck (threaddump) and if that doesn't give any quick answers, turn on the profiler.
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
What container are you using? c3p0 should be installed in the container, e.g Tomcat. If you are running unit tests, for chrissakes, don't use a connection pool. If you put it into tomcat, you do that with a Resource tag and then connect to it using JNDI. Best way to do it.
See Hibernate Slow to Acquire Postgres Connection
hibernate.temp.use_jdbc_metadata_defaults=false
To avoid meta-data reload during SessionFactory creation.
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.