简体   繁体   中英

Unable to build Hibernate SessionFactory no apparent cause

I am really struggling with an issue with spring boot and hibernate. I am getting this error:

AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory

I was thinking that the app can't connect to the mysql database, but that does not seem to be the case because flyway is able to connect and run migration scripts.

[INFO ] 2020-01-21_11:18:39.293 [main] VersionPrinter - Flyway Community Edition 5.0.7 by Boxfuse
[INFO ] 2020-01-21_11:18:39.304 [main] HikariDataSource - HikariPool-1 - Starting...
[INFO ] 2020-01-21_11:18:39.534 [main] HikariDataSource - HikariPool-1 - Start completed.
[INFO ] 2020-01-21_11:18:39.548 [main] DatabaseFactory - Database: jdbc:mysql://someIpHere:3306/someDatabaseNameHere (MySQL 5.6)
[INFO ] 2020-01-21_11:18:40.357 [main] DbValidate - Successfully validated 354 migrations (execution time 00:00.729s)
[INFO ] 2020-01-21_11:18:40.434 [main] DbMigrate - Current version of schema `someDatabaseNameHere `: 339
[WARN ] 2020-01-21_11:18:40.434 [main] DbMigrate - outOfOrder mode is active. Migration of schema `someDatabaseNameHere` may not be reproducible.
[INFO ] 2020-01-21_11:18:40.438 [main] DbMigrate - Schema `someDatabaseNameHere ` is up to date. No migration necessary.
[INFO ] 2020-01-21_11:18:40.622 [main] LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'default'
[INFO ] 2020-01-21_11:18:40.640 [main] LogHelper - HHH000204: Processing PersistenceUnitInfo [
    name: default

The weird part is that if i run the exact same jar on another machine, it works. The logs look the same until i get the error.

Error logs:

[INFO ] 2020-01-21_11:18:40.622 [main] LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'default'
[INFO ] 2020-01-21_11:18:40.640 [main] LogHelper - HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
[INFO ] 2020-01-21_11:18:40.718 [main] Version - HHH000412: Hibernate Core {5.2.14.Final}
[INFO ] 2020-01-21_11:18:40.720 [main] Environment - HHH000206: hibernate.properties not found
[INFO ] 2020-01-21_11:18:40.764 [main] Version - HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
[INFO ] 2020-01-21_11:18:41.242 [main] Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
[WARN ] 2020-01-21_11:18:42.253 [main] AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
[INFO ] 2020-01-21_11:18:42.254 [main] HikariDataSource - HikariPool-1 - Shutdown initiated...
[INFO ] 2020-01-21_11:18:42.264 [main] HikariDataSource - HikariPool-1 - Shutdown completed.
[INFO ] 2020-01-21_11:18:42.266 [main] StandardService - Stopping service [Tomcat]

No error logs:

[INFO ] 2020-01-21_12:19:31.394 [main] LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'default'
[INFO ] 2020-01-21_12:19:31.417 [main] LogHelper - HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
[INFO ] 2020-01-21_12:19:31.510 [main] Version - HHH000412: Hibernate Core {5.2.14.Final}
[INFO ] 2020-01-21_12:19:31.512 [main] Environment - HHH000206: hibernate.properties not found
[INFO ] 2020-01-21_12:19:31.564 [main] Version - HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
[INFO ] 2020-01-21_12:19:31.986 [main] Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
[INFO ] 2020-01-21_12:19:34.093 [main] LocalContainerEntityManagerFactoryBean - Initialized JPA EntityManagerFactory for persistence unit 'default'
[INFO ] 2020-01-21_12:19:34.499 [main] cluster - Cluster created with settings {hosts=[someHost:27017, someHost:27017, someHost:27017, someHost:27017, someHost:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[INFO ] 2020-01-21_12:19:34.500 [main] cluster - Adding discovered server someHost:27017 to client view of cluster

I'm really stuck on this. I can't find an actual cause for the PersistenceException, even when running with logging level TRACE. As well, i can't find this exact exception behaviour anywhere on the internet, most of the time it's related to a bad config and the logs provide additional details. It has to be something related to the machine, but i can't figure out what and i can't get any more information from the logs.

if you are running it on an external server, then download latest version of Tomcat.it could be version mismatch. this might help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM