users@glassfish.java.net

RE: Glassfish 3.1.1, Hibernate 3.6.7, Hibernate Search 3.4.1 - no persistence provider

From: Chris Oman <COman_at_ext-inc.com>
Date: Tue, 30 Aug 2011 19:04:59 -0700

While attempting to get EclipseLink working in the fashion I needed, Sahoo pointed me section 8 of this document (http://wikis.sun.com/download/attachments/209655166/GF-OSGi-Features-1.0.pdf). Following these directions and further conversations with Sahoo on this email list is what led to that snippet of code. It is first run during the bundle activator start method. It is also run anytime after when attempting to connect to a different database file.

As stated before, this works just fine with EclipseLink. However, I need to switch to Hibernate so that I can use Hibernate Search. According to the documentation, it should be a trivial exercise. Supposedly I just need to copy the Hibernate files and dependencies to the domain_dir/lib folder and then change the provider in the persistence.xml file as I have. But that is what is causing the exception.

________________________________________
From: Mitesh Meswani [mitesh.meswani_at_oracle.com]
Sent: Tuesday, August 30, 2011 4:46 PM
To: users_at_glassfish.java.net
Subject: Re: Glassfish 3.1.1, Hibernate 3.6.7, Hibernate Search 3.4.1 - no persistence provider

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);
>