Hibernate startup very slow

前端 未结 5 1300
遇见更好的自我
遇见更好的自我 2020-12-15 17:20

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)

相关标签:
5条回答
  • 2020-12-15 17:46

    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.

    0 讨论(0)
  • 2020-12-15 17:53

    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

    0 讨论(0)
  • 2020-12-15 17:54

    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.

    0 讨论(0)
  • 2020-12-15 18:04

    See Hibernate Slow to Acquire Postgres Connection

    hibernate.temp.use_jdbc_metadata_defaults=false

    To avoid meta-data reload during SessionFactory creation.

    0 讨论(0)
  • 2020-12-15 18:07

    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.

    0 讨论(0)
提交回复
热议问题