【问题标题】:Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed在类路径资源中定义名称为“entityManagerFactory”的 bean 创建错误:调用 init 方法失败
【发布时间】:2017-02-24 18:16:53
【问题描述】:

当我编译我的 spring 项目时,我得到了以下错误。

在类中定义名称为“entityManagerFactory”的 bean 创建错误 路径资源 [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: init方法调用失败

我正在使用 STS Eclipse 和 MySql 数据库

Application.Properties 中的我的连接字符串是

spring.datasource.url=jdbc:mysql://localhost:3306/stgdb
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update

下面给出详细的错误

=================================================

2016-10-15 15:34:38.875[0;39m [31mERROR[0;39m [35m3700[0;39m [2m---[0;39m [2m[           main][0;39m [36mo.s.boot.SpringApplication              [0;39m [2m:[0;39m Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at com.s2g.testrestapplication.TestRestApplication.main(TestRestApplication.java:10) [classes/:na]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    ... 16 common frames omitted
Caused by: org.hibernate.exception.GenericJDBCException: Unable to obtain JDBC Connection
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.ExtractionContextImpl.getJdbcConnection(ExtractionContextImpl.java:65) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.ExtractionContextImpl.getJdbcDatabaseMetaData(ExtractionContextImpl.java:75) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.locateTableInNamespace(InformationExtractorJdbcDatabaseMetaDataImpl.java:339) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.getTable(InformationExtractorJdbcDatabaseMetaDataImpl.java:241) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.getTableInformation(DatabaseInformationImpl.java:105) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:162) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:60) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:134) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:101) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:472) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
    ... 22 common frames omitted
Caused by: com.atomikos.jdbc.AtomikosSQLException: Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on the DataSourceBean.
    at com.atomikos.jdbc.AtomikosSQLException.throwAtomikosSQLException(AtomikosSQLException.java:46) ~[transactions-jdbc-3.9.3.jar:na]
    at com.atomikos.jdbc.AbstractDataSourceBean.throwAtomikosSQLException(AbstractDataSourceBean.java:90) ~[transactions-jdbc-3.9.3.jar:na]
    at com.atomikos.jdbc.AbstractDataSourceBean.throwAtomikosSQLException(AbstractDataSourceBean.java:85) ~[transactions-jdbc-3.9.3.jar:na]
    at com.atomikos.jdbc.AbstractDataSourceBean.getConnection(AbstractDataSourceBean.java:347) ~[transactions-jdbc-3.9.3.jar:na]
    at com.atomikos.jdbc.AbstractDataSourceBean.getConnection(AbstractDataSourceBean.java:394) ~[transactions-jdbc-3.9.3.jar:na]
    at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.ExtractionContextImpl.getJdbcConnection(ExtractionContextImpl.java:62) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    ... 33 common frames omitted
==============================
Pom.xml file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.s2g.testrestapplication</groupId>
    <artifactId>testrestapplication</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>TestRestApplication</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.opensaml</groupId>
            <artifactId>opensaml-saml-api</artifactId>
            <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jta-atomikos</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

【问题讨论】:

  • 很明显,你得到的“错误”实际上是“由:com.atomikos.jdbc.AtomikosSQLException:连接池耗尽 - 尝试增加 DataSourceBean 上的 'maxPoolSize' 和/或 'borrowConnectionTimeout'。”

标签: java spring hibernate spring-mvc jpa


【解决方案1】:

我将从添加以下依赖项开始:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.1.4.Final</version>
</dependency>

和

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.2.3.Final</version>
</dependency>

更新:或者干脆添加以下依赖。

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>

【讨论】:

  • @georges-van 我遇到了同样的错误,并且您提到的 2 个依赖项已经存在于 spring-boot-starter-data-jpa 中,我收到以下错误。 anotepad.com/notes/wpjr5g
  • 只要使用帖子中提到的相同版本即可。
  • @georges,thevikasdube 已经在使用包含 Hibernate 的 spring-boot-starter-data-jpa 依赖项。有什么理由他应该明确包括休眠依赖项??
  • 仅供参考 hibernate-entitymanager 现已弃用。请使用(仅)hibernate-core。
  • 谢谢,我添加了这个并且它起作用了- javax.xml.bindjaxb-api[2.3.0, ]
【解决方案2】:

使用 Java 9 的人包含此依赖项:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>

【讨论】:

  • 对于那些对 Java 8 之后的版本为什么需要明确包含感兴趣的人,这里有一篇有趣的文章; baeldung.com/java-9-jaxbexception ,基本上它与 Java 9s 引入模块化系统有关,并试图精简所有不必要的库......
  • 这对我有用,即使我使用的是 Java 8,谢谢。
  • 这对于 gradle 可能是什么?
【解决方案3】:

添加依赖项并没有解决我的问题。

问题发生在我的最后,因为“@Entity”类中的“附加”字段不存在于数据库中。

我从@Entity 类中删除了附加字段,它起作用了。

祝你好运。

【讨论】:

  • 你所说的附加字段是什么意思?你能提供更多关于这方面的信息吗?我现在也有同样的问题
  • 我的意思是数据库中不存在的其他属性,例如私有/公共整数..等
  • 工作!在我的 Entity 类中,有两个构造函数(arg,no-arg)。我删除了它们并且它起作用了。谢谢@JAD。快乐编码。
  • 是的,此问题可能与任何实体类中的问题有关。
  • 成功了!该错误不是依赖项或实体管理器配置问题。问题是我的实体类之一。在持久性管理器的帮助下创建了实体类后,问题就解决了。谢谢。
【解决方案4】:

我怀疑 hibernate-core 和 hibernate-entitymanager 依赖项的 jar 文件已损坏或未正确安装在您的计算机上。

我建议您只需从您的 Maven 本地存储库中删除名为 hibernate-core 和 hibernate-entitymanager 的文件夹,然后 Maven 将重新安装它们。

Maven 本地存储库的默认位置是 Windows 中的 C:\Documents and Settings\[USERNAME]\.m2 或 Linux/Mac 中的 ~/.m2。

【讨论】:

  • 它对我有用,我已将 Spring Boot 版本从 1.5 更新到 2.3,并收到此错误。
  • 我删除了我的完整存储库,它可以工作。它解决了这个问题以及 spring boot 的许多其他错误
【解决方案5】:

我有jdk-12.0.2.jdk,已经找到解决问题的办法,给pom.xml添加依赖:

<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.javassist/javassist -->
<dependency>
    <groupId>org.javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.25.0-GA</version>
</dependency>

【讨论】:

  • 谢谢,我也使用 JDK 12,这是唯一适合我的。
  • 谁能解释为什么添加这些依赖项可以解决我们中的一些人的错误?
  • 这个修复了我的。谢谢。
【解决方案6】:

例如,在我的情况下,删除以下任何注释都会导致显示错误消息“entityManagerFactory”。

 @Id
  @GeneratedValue(strategy=GenerationType.AUTO)

或

@ManyToMany(targetEntity=listOfObject_x.class)

添加缺少的注释后错误消息消失。

package mypackage_unameit;
import javax.persistence.PrePersist;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import lombok.Data;

@Data
@Entity
public class Someclasss {

  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  private Long id;

  @NotNull
  @Size(min=5, message="Name must be at least 5 characters long")
  private String name;

  private Date createdAt;

  @ManyToMany(targetEntity=listOfObject_x.class)
  @Size(min=1, message="You must choose at least 1 ingredient")
  private List<listOfObject_x>   = new ArrayList<>();

  @PrePersist
  void createdAt() {
    this.createdAt = new Date();
  }
}

【讨论】:

    【解决方案7】:

    我通过将 spring 依赖项版本从 2.0.4 更新到 2.1.6 解决了我的问题

    <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.4.RELEASE</version>
            <relativePath /> <!-- lookup parent from repository -->
    </parent>
    

    到

    <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.6.RELEASE</version>
            <relativePath /> <!-- lookup parent from repository -->
    </parent>
    

    【讨论】:

    • 我尝试了上述所有解决方案,但只有这个对我有用!拯救我的一天!!!
    【解决方案8】:

    对于那些不使用 JPA 而更喜欢排除 entityManagerFactory 并使用 Spring Data JDBC 或 Spring JDBC 的人可以排除 bean 以避免异常

    @SpringBootApplication(exclude = {HibernateJpaAutoConfiguration.class})
    

    【讨论】:

      【解决方案9】:

      对于那些使用 Gradle 而不是 Maven 的人,请将其添加到构建文件中的依赖项中:

      compile('javax.xml.bind:jaxb-api:2.3.0')
      

      【讨论】:

        【解决方案10】:

        就我而言,这是由于 Intellij IDEA 默认将 Java 11 设置为默认项目 SDK,但项目是在 Java 8 中实现的。 我在文件 -> 项目结构 -> 项目(在项目设置中)中更改了“项目 SDK”

        【讨论】:

        • 这也是我的问题,当您尝试使用新下载的 IntellijIDEA 打开使用 Java8 的旧项目时,这就是解决方案。
        • 在 macOS 上安装 Java8 - brew cask install 采用openjdk/openjdk/adoptopenjdk8
        【解决方案11】:

        我能够通过将最大池大小值从 1 更改为 2 来解决问题

        spring.datasource.hikari.maximum-pool-size=2

        【讨论】:

          【解决方案12】:

          尝试使用@EnableTransactionManagement 注释类。我遇到了同样的问题,通过添加它得到了解决。

          @EnableTransactionManagement
          public class ConfigurationBean {
          }
          

          【讨论】:

            【解决方案13】:

            如果您使用 JDK 1.8.0_201 或最新版本,请尝试使用旧版 JDK。

            我对 JDK1.8.0_201 有同样的问题,但是它可以在 JDK1.8.0_101 上使用,无需任何代码更改。

            【讨论】:

              【解决方案14】:

              我通过在模型中添加实现 Serializable 解决了这个问题。

              @Entity
              @Table(name="Model_Rest")
              @IdClass(Model_Rest.class)
              public class Model_Rest implements Serializable {
              
                  /**
                   * 
                   */
                  private static final long serialVersionUID = 1L;
                  /**
                   * 
                   */
                  //@GeneratedValue(strategy = GenerationType.AUTO)
                  //@Column(columnDefinition="id")
              
                  @Id
                  private String login;
                  @Id
                  private String password;
              
              
              
              
                  @Autowired
                  public String getLogin() {
                      return login;
                  }
              
                  @Autowired
                  public void setLogin(String login) {
                      this.login = login;
                  }
              
                  @Autowired
                  public String getPassword() {
                      return password;
                  }
              
                  @Autowired
                  public void setPassword(String password) {
                      this.password = password;
                  }
              
                  public Model_Rest() {
                      // TODO Auto-generated constructor stub
                  }
              
                  public Model_Rest(String login, String password) {
                      this.login = login;
                      this.password = password;
                  }
              
                  @Override
                  public String toString() {
                      return "Model_Rest [login=" + login + ", password=" + password + "]";
                  }
                }
              

              【讨论】:

                【解决方案15】:

                此错误也可能与您在“spring.datasource.url”中出现错误有关,例如当您提供错误的数据库名称时

                【讨论】:

                  【解决方案16】:

                  我在 Eclipse Luna 上遇到了同样的问题。 我发现我使用的是 JDK12 和 Java 1.8。我把JDK换成JDK8,问题就解决了。 如果您想在 Eclipse 中检查您的 JDK,请转到

                  Window-> Preferences-> Java- >Installed JREs 
                  

                  并检查它们是否与您的项目兼容。 祝你好运!

                  【讨论】:

                  • 同样,我发现我使用的是 JDK 12 并且刚刚切换回 JDK 8 并且工作正常
                  【解决方案17】:

                  对我来说,它是 application.properties 上的数据库名称。当我提供正确的名称时,它工作正常。

                  【讨论】:

                    【解决方案18】:

                    谁仍然有同样的问题。请在 application.properties 中添加以下行

                    # The SQL dialect makes Hibernate generate better SQL for the chosen database
                    ## I am using Mysql8 so I have declared MySQL8Dialect if you have other versions just add ## that version number
                    spring.jpa.properties.hibernate.dialect =  org.hibernate.dialect.MySQL8Dialect
                    
                    

                    【讨论】:

                      【解决方案19】:

                      在我的情况下,我在 application.properties 中添加以下行 ,问题出在 Oracle 11g DB 驱动程序中

                      spring.jpa.database-platform=org.hibernate.dialect.OracleDialect
                      

                      【讨论】:

                      • 谢谢,它解决了我的问题 :)
                      【解决方案20】:

                      我们在映射一列时,要注意被映射的对面列的名称,例如:

                      /*users*/
                      @OneToMany(mappedBy = "partModel")
                      private List<UsersModel> usersModels;
                      
                      
                      /*parts*/
                      @ManyToOne
                      private PartModel partModel;
                      

                      在此处查看 postModel。***

                      【讨论】:

                        【解决方案21】:

                        使用@Id 。为我工作。否则我会抛出错误。这取决于您的实体类或存储库中是否缺少任何东西

                        【讨论】:

                          【解决方案22】:

                          对我来说,这是另一个错误的结果

                          org.postgresql.util.PSQLException: FATAL: 用户密码验证失败

                          这意味着您只需要检查您的身份验证凭据

                          【讨论】:

                            【解决方案23】:

                            添加此依赖项后,我的错误已解决。

                            <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
                                <dependency>
                                    <groupId>org.hibernate.validator</groupId>
                                    <artifactId>hibernate-validator</artifactId>
                                    <version>6.0.16.Final</version>
                                </dependency>
                            

                            【讨论】:

                              【解决方案24】:

                              尝试更改 spring 版本。我有同样的问题,这对我有用

                              【讨论】:

                                【解决方案25】:

                                我通过为附加字段定义反向关系注释解决了我的问题

                                【讨论】:

                                  【解决方案26】:

                                  在我的情况下,我在尝试使 Proguard + Spring Boot 2 工作时遇到了这个错误。

                                  将-dontusemixedcaseclassnames 添加到 proguard.conf 修复它。

                                  【讨论】:

                                    【解决方案27】:

                                    在我们的例子中,我们在 .properties 文件中有一些额外的行,新图像不需要这些行。

                                    spring.jpa.properties.hibernate.cache.use_second_level_cache=true

                                    显然没有该实体尝试加载的内容。

                                    【讨论】:

                                      【解决方案28】:

                                      如果没有任何效果,那么我有一个解决方案 @Access(值=AccessType.FIELD) 在您使用 @Entity 之后在模型类下添加这一行,然后在定义 id 时添加该类和类之后,并且一直使用上述行。

                                      【讨论】:

                                        【解决方案29】:

                                        在我的情况下,问题是多方面的,并且与 AWS 有关:

                                        1. 正如@Tareq Islam 指出的那样,在 application.properties 中设置方言很有帮助。我用于 MySQL 5.6:

                                          spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL55Dialect

                                        2. 这之后的第二个问题是,由于 SSL 连接加密的更改,JDBC 无法连接到服务器。我在

                                          的帮助下修复了它

                                        SSLHandShakeException No Appropriate Protocol

                                        但我需要通过设置为 /etc/java-11-openjdk/security/java.security 来启用 TLS1.0

                                        jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL
                                        

                                        【讨论】:

                                          【解决方案30】:
                                          Make sure you have successfully build dependent maven/gradle based project with the correct mention version. Similarly you can add the dependent project in config like below.
                                          
                                                  @Bean
                                                  @Primary
                                                  public LocalContainerEntityManagerFactoryBean entityManager() {
                                                      EntityManagerFactoryBuilder builder = new 
                                                      EntityManagerFactoryBuilder(adapter, jpaProperties.getProperties(),
                                                          persistenceUnitManager);
                                                      return builder
                                                          .dataSource(dataSources()).packages("com.ABCApi.entity",
                                                              "com.PQRApi.entity", "com.XYZApi.entity")
                                                          .persistenceUnit("entityManager").build();
                                                  }
                                          

                                          【讨论】:

                                            猜你喜欢
                                            • 2020-03-23
                                            • 2019-11-19
                                            • 1970-01-01
                                            • 2015-10-16
                                            • 2014-03-09
                                            • 2016-02-17
                                            • 1970-01-01
                                            相关资源
                                            最近更新 更多