Where is the code snippet you mentioned being executed? Why are you
setting context classloader before calling Persistence.createEMF() ?
On 8/30/2011 1:11 PM, Chris Oman wrote:
> I am attempting to use Hibernate as a JPA provider in a Java SE manner inside of our bundle. The reason for this is that we may have multiple different database files to connect with over time so this can't be defined as a JNDI/JTA datasource. This works fine with the built-in EclipseLink.
>
> My problem is that when I call
> emFactory = Persistence.createEntityManagerFactory("audit", properties);
>
> I am rewarded with the error
> javax.persistence.PersistenceException: No Persistence provider for EntityManager named audit
> at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
>
>
> I have copied HIbernate and all of its required libraries into our domain_dir/lib directory and changed the provider property in the persistence.xml file. What else needs to be done?
>
>
> Here is persistence.xml:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
> version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
> <persistence-unit name="audit" transaction-type="RESOURCE_LOCAL">
> <provider>
> org.hibernate.ejb.HibernatePersistence
> </provider>
> <class>
> xxx
> </class>
> <class>
> yyyy
> </class>
> <class>
> zzzz
> </class>
> <properties>
> <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
> <property name="javax.persistence.jdbc.user" value="aaa" />
> <property name="javax.persistence.jdbc.password" value="bbb" />
> <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
> <property name="hibernate.hbm2ddl.auto" value="update" />
> </properties>
> </persistence-unit>
> </persistence>
>
>
> Additionally, here is the code that attempts to create the EntityManagerFactory:
>
> ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
> Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
> emFactory = Persistence.createEntityManagerFactory("audit", properties);
> Thread.currentThread().setContextClassLoader(originalClassLoader);
>