I have my persistence.xml
with the same name using TopLink
under the META-INF
directory.
Then, I have my code calling it with:
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.
Make sure that the persistence.xml
file is in the directory: <webroot>/WEB-INF/classes/META-INF
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.
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
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.
Quick advice:
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:
<provider>org.hibernate.ejb.HibernatePersistence</provider>
(as described in correct answere by Chris: https://stackoverflow.com/a/1285436/784594)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.