No Persistence provider for EntityManager named

前端 未结 30 1985
甜味超标
甜味超标 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:21

    Put the "hibernate-entitymanager.jar" in the classpath of application.
    For newer versions, you should use "hibernate-core.jar" instead of the deprecated hibernate-entitymanager

    If you are running through some IDE, like Eclipse: Project Properties -> Java Build Path -> Libraries.

    Otherwise put it in the /lib of your application.

    0 讨论(0)
  • 2020-11-22 04:21

    Make sure that the persistence.xml file is in the directory: <webroot>/WEB-INF/classes/META-INF

    0 讨论(0)
  • 2020-11-22 04:26

    You need to add the hibernate-entitymanager-x.jar in the classpath.

    In Hibernate 4.x, if the jar is present, then no need to add the org.hibernate.ejb.HibernatePersistence in persistence.xml file.

    0 讨论(0)
  • 2020-11-22 04:29

    If you're using Maven, it could be that it is not looking at the right place for the META-INF folder. Others have mentioned copying the folder, but another way that worked for me was to tell Maven where to look for it, using the <resources> tag. See: http://maven.apache.org/plugins/maven-resources-plugin/examples/resource-directory.html

    0 讨论(0)
  • 2020-11-22 04:29

    The question has been answered already, but just wanted to post a tip that was holding me up. This exception was being thrown after previous errors. I was getting this:

    property toplink.platform.class.name is deprecated, property toplink.target-database should be used instead.
    

    Even though I had changed the persistence.xml to include the new property name:

    <property name="toplink.target-database" value="oracle.toplink.platform.database.oracle.Oracle10Platform"/>
    

    Following the message about the deprecated property name I was getting the same PersistenceException like above and a whole other string of exceptions. My tip: make sure to check the beginning of the exception sausage.

    There seems to be a bug in Glassfish v2.1.1 where redeploys or undeploys and deploys are not updating the persistence.xml, which is being cached somewhere. I had to restart the server and then it worked.

    0 讨论(0)
  • 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: <provider>org.hibernate.ejb.HibernatePersistence</provider> (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.

    0 讨论(0)
提交回复
热议问题