0

I m trying to implement hibernate-osgi with Equinox.

I've created a plugin "my.app.hibernate.osgi" from the following jars: jars of my.app.hibernate.osgi

  • antlr-2.7.7.jar
  • byte-buddy-1.6.14.jar
  • classmate-1.3.0.jar
  • dom4j-1.6.1.jar
  • hibernate-commons-annotations-5.0.1.Final.jar
  • hibernate-core-5.2.16.Final.jar
  • hibernate-jpa-2.1-api-1.0.0.Final.jar
  • hibernate-osgi-5.2.16.Final.jar
  • jandex-2.0.3.Final.jar
  • javassist-3.22.0-GA.jar
  • javax.interceptor-api-1.2.jar
  • jboss-logging-3.3.1.Final.jar
  • jboss-transaction-api_1.2_spec-1.0.1.Final.jar
  • junit-3.8.1.jar
  • validation-api-2.0.1.Final.jar

In the MANIFEST.MF of this plugin I've added the following:

Bundle-Name: my.app.hibernate.osgi
Bundle-SymbolicName: my.app.hibernate.osgi;singleton:=true
Bundle-Activator: org.hibernate.osgi.HibernateBundleActivator
Bundle-ActivationPolicy: lazy
Eclipse-BuddyPolicy: registered

Then I've created another plugin "my.app.core.hibernate" for my hibernate configuration, Entities and DAOs

In the MANIFEST.MF of this one, it is like this:

Bundle-Activator: my.app.core.hibernate.Activator
Bundle-ActivationPolicy: lazy
Eclipse-RegisterBuddy: my.app.hibernate.osgi
Require-Bundle: my.app.hibernate.osgi
 org.eclipse.e4.ui.model.workbench,
 org.eclipse.e4.core.services,
 org.eclipse.osgi,
 org.eclipse.core.runtime,
 org.eclipse.osgi.services,
 org.eclipse.core.net,
...
Meta-Persistence: META_INF/persistence.xml

And my persistence.xml :

<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="myAppPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
     ...
  </persistence-unit>
</persistence>

I have also a EntityManagerService to get EntityManager

private static EntityManagerFactory getEntityManagerFactory() {
    if ( emf == null ) {
        Bundle thisBundle = FrameworkUtil.getBundle( EntityManagerService.class );
        BundleContext context = thisBundle.getBundleContext();

        ServiceReference serviceReference = context.getServiceReference( PersistenceProvider.class.getName() );
        PersistenceProvider persistenceProvider = (PersistenceProvider) context.getService( serviceReference );

        emf = persistenceProvider.createEntityManagerFactory( "myAppPU", null );
    }
    return emf;
}

Finally I have a third plugin "my.app.core" that uses my DAOs. With the following MANIFEST.MF :

Eclipse-RegisterBuddy: my.app.hibernate.core
Bundle-ActivationPolicy: lazy
Require-Bundle: my.app.core.hibernate,
 org.eclipse.e4.core.di;bundle-version="1.5.0",
 org.eclipse.fx.core.di;bundle-version="2.2.0",
 org.eclipse.e4.ui.di;bundle-version="1.1.0",
 org.eclipse.osgi.services,
 org.eclipse.e4.core.contexts,
 org.apache.log4j,
 javax.inject,
 org.apache.commons.lang,
 org.eclipse.equinox.app

When I start my app

    emf = persistenceProvider.createEntityManagerFactory( "myAppPU", null );

the entityManagerFactory is null

What am I doing wrong?

(Edited:) I figured out (while debugging the hibernate code) that in ProviderChercker the following line returns null:

    final String setting = (String) integration.get( AvailableSettings.PROVIDER );

What provider should I declare in the persistence.xml ?

I m using a embedded H2 db V.1.4.197

(Also, I m not sure whether I should include the two following jars org.osgi.compendium-4.3.1.jar and org.osgi.core-4.3.1.jar to my "my.app.hibernate.osgi" plugin. I've tried but in that case I have a ClassCastException : HibernateBundleActivator cannot be cast to BundleActivator)

Zibus69
  • 1
  • 2

1 Answers1

0

The provider name was bad. The good one:

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
Zibus69
  • 1
  • 2