Hibernate 启动慢

目录
  1. 问题
  2. 解决

问题

项目使用PostgreSQL+Hibernate+Spring Boot, 发现启动过慢,有如下日志。

1
2
3
2018-01-18 21:49:31.625 [main] INFO  org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL95Dialect

2018-01-18 21:50:02.964 [main] INFO o.h.engine.jdbc.env.internal.LobCreatorBuilderImpl - HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException

Disabling contextual LOB creation as createClob() method threw error 费时且没用。

解决

Spring Boot项目中添加如下配置

1
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults: false

添加配置后启动,启动时间可大大缩短。

1
2
3
2018-01-18 21:45:43.852 [main] INFO  org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect

2018-01-18 21:45:43.873 [main] INFO o.h.engine.jdbc.env.internal.LobCreatorBuilderImpl - HHH000422: Disabling contextual LOB creation as connection was null