解決集成jpa時報錯無法創建少導入entityManagerFactory的問題
阿新 • • 發佈:2018-10-07
fault ati ould pat 無法 path 導入 reat -o 解決集成jpa時報錯無法創建少導入entityManagerFactory的問題
最近將IDEA 2018.1版本更新到了2018.2版本,更新好後跑了一下之前的項目,結果就報錯了,這個項目集成了spring data jpa。由於該錯誤有多種原因導致,在解決該錯誤的時候也花了一些時間,所以特別記錄一下。關鍵的報錯信息如下:
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。
http://stackoverflow.com/questions/18042247/could-not-get-constructor-for-org-hibernate-persister-entity-singletableentitype
-
沒有導入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>
引入了這個jar包後,啟動就正常了。
解決集成jpa時報錯無法創建少導入entityManagerFactory的問題