简体   繁体   English

无法构建 Hibernate SessionFactory 没有明显原因

[英]Unable to build Hibernate SessionFactory no apparent cause

I am really struggling with an issue with spring boot and hibernate.我真的很努力解决 spring boot 和 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.我在想该应用程序无法连接到 mysql 数据库,但似乎并非如此,因为 flyway 能够连接并运行迁移脚本。

[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.奇怪的是,如果我在另一台机器上运行完全相同的 jar,它就可以工作。 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.我找不到 PersistenceException 的实际原因,即使在使用日志记录级别 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.如果您在外部服务器上运行它,则下载最新版本的 Tomcat。它可能是版本不匹配。 this might help you 这可能会帮助你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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