2023-06-10 21:29:04.460 WARN 24060 --- [ main] ConfigServletWebServerApplicationContext : 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; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister 2023-06-10 21:29:04.468 INFO 24060 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closed 2023-06-10 21:29:04.509 INFO 24060 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
无法初始化 JPA EntityManagerFactory:无法创建请求的服务 [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
或者
Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
或
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/zero/xunwuproject/config/JpaConfig.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
这个错误有多种原因导致,在网上查了一下, 大概有以下几种原因:
-
实体类的属性对象没有设置setter或者getter。
-
没有导入javassist的jar文件 (javassist-3.15.0-GA.jar什么的)
http://blog.csdn.net/xiaochangwei789/article/details/7712725
- 实体类中的属性对象名和映射文件的property name不一致。
https://blog.csdn.net/liuzhengyang1/article/details/23127629
而我这里是第二个原因,缺少javassist的jar包,于是在pom文件中引入:
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.23.1-GA</version>
</dependency>
解决办法:缺少 javassist-3.15.0-GA.jar 包,版本未定。引入了这个jar包后,启动就正常了。
标签:EntityManagerFactory,hibernate,get,JPA,jar,entity,org,javassist From: https://www.cnblogs.com/Fooo/p/17472024.html