【发布时间】:2019-02-21 20:20:54
【问题描述】:
我想使用 entiies 和 jpa 来处理我的数据库。
当我只是想在 SpringConfig.java 中创建 bean 时:
@Bean
@Singleton
public EntityManager getEntityManager(){
return Persistence.createEntityManagerFactory("collection").createEntityManager();
}
我有:
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named collection: No META-INF/persistence.xml was found in classpath.
但名称“collection”与 persistence-unit 中的名称相同
我的 persistence.xml 位于 resources (src/main/resources) 并配置为 jpa in弹簧靴
更新:
当我尝试将 persistence.xml 放入资源/META-INF/ 时,我遇到了另一个例外:
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named collection: Provider named org.hibernate.jpa.HibernatePersistenceProvider threw unexpected exception at create EntityManagerFactory:
java.lang.NoSuchMethodError
【问题讨论】: