No Persistence provider for EntityManager named

前端 未结 30 2024
甜味超标
甜味超标 2020-11-22 03:45

I have my persistence.xml with the same name using TopLink under the META-INF directory. Then, I have my code calling it with:

30条回答
  •  别跟我提以往
    2020-11-22 04:30

    Quick advice:

    • check if persistence.xml is in your classpath
    • check if hibernate provider is in your classpath

    With using JPA in standalone application (outside of JavaEE), a persistence provider needs to be specified somewhere. This can be done in two ways that I know of:

    • either add provider element into the persistence unit: org.hibernate.ejb.HibernatePersistence (as described in correct answere by Chris: https://stackoverflow.com/a/1285436/784594)
    • or provider for interface javax.persistence.spi.PersistenceProvider must be specified as a service, see here: http://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html (this is usually included when you include hibernate,or another JPA implementation, into your classpath

    In my case, I found out that due to maven misconfiguration, hibernate-entitymanager jar was not included as a dependency, even if it was a transient dependency of other module.

提交回复
热议问题