users@glassfish.java.net

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

From: Sahoo <sanjeeb.sahoo_at_oracle.com>
Date: Fri, 02 Sep 2011 22:07:57 +0530

Ideally Hibernate should supply the bundle. I really hope someone from
GlassFish JPA team helps you in making a bundle. You should be able to
look at how we make a bundle out of bean validator [1] and go from
there. I can try to do it when I have time.

Thanks,
Sahoo

[1] https://svn.java.net/svn/hk2~svn/trunk/hk2/external/bean-validator

On Thursday 01 September 2011 01:37 AM, Chris Oman wrote:
> I have attempted a) below and spent the better part of the day tracking own the Hibernate
> dependencies and getting the import-package directive correct.
>
> I have run into a brick wall that I can't seem to overcome. When the bundle starts up and
> executes the code snippet below, I get the following error:
>
> java.lang.NoClassDefFoundError: org/w3c/dom/Node
> at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:317)
> at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
> at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
>
> That class is part of the runtime, so why can't it find it?
>
> Chris
>
> On Aug 31, 2011, at 3:15 AM, Sahoo wrote:
>
>> Chris,
>>
>> Your app works for EclipseLink, because EclipseLink is installed as an
>> OSGi bundle in GlassFish. jars in domain/lib are not typically visible
>> to OSGi bundles in GlassFish. You have two choices:
>>
>> a) Embed Hibernate in your bundle.
>>
>> b) Make a bundle out of Hibernate jars and install them in GlassFish.
>> GlassFish discovers persistence providers by existence of
>> META-INF/services/javax.persistence.PersistenceProvider file in it. You
>> may even find such bundle available by Hibernate; I am not sure.
>>
>> Sahoo
>>
>> On Wednesday 31 August 2011 07:34 AM, Chris Oman wrote:
>>> 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);
>>>>