brmeyer / HibernateOSGi

14 stars 11 forks source link

NPE on createEntityManager #3

Closed lburgazzoli closed 11 years ago

lburgazzoli commented 11 years ago

I've installed the following bundles in Karaf 2.3.0

[ 76] [Active ] [ ] [ 80] Commons Lang (3.1.0) [ 83] [Active ] [ ] [ 80] HSQLDB (2.2.9) [ 109] [Active ] [ ] [ 80] Guava: Google Core Libraries for Java (13.0.0) [ 130] [Active ] [ ] [ 80] Apache ServiceMix :: Bundles :: serp (1.14.1.1) [ 132] [Active ] [ ] [ 80] geronimo-servlet_2.5_spec (1.2) [ 134] [Active ] [ ] [ 80] Commons Collections (3.2.1) [ 135] [Active ] [ ] [ 80] Apache ServiceMix :: Bundles :: commons-dbcp (1.4.0.3) [ 136] [Active ] [ ] [ 80] Commons Lang (2.6) [ 137] [Active ] [ ] [ 80] Commons Pool (1.5.4) [ 138] [Active ] [ ] [ 80] OpenJPA Aggregate Jar (2.2.1) [ 182] [Active ] [ ] [ 80] ClassMate (0.5.4) [ 184] [Active ] [ ] [ 80] Hibernate Validator (4.2.0.Final) [ 185] [Active ] [ ] [ 80] Apache Geronimo JSR-303 Bean Validation Spec API (1.1) [ 186] [Active ] [ ] [ 80] Apache ServiceMix :: Bundles :: antlr (2.7.7.5) [ 187] [Active ] [ ] [ 80] Apache ServiceMix :: Bundles :: ant (1.8.2.2) [ 188] [Active ] [ ] [ 80] Apache ServiceMix :: Bundles :: dom4j (1.6.1.5) [ 189] [Active ] [ ] [ 80] Javassist Java Programming Assistant (3.15.0.GA) [ 190] [Active ] [ ] [ 80] JACC 1.4 API (1.0.2.Final) [ 191] [Active ] [ ] [ 80] wrap_mvn_org.jboss_jandex_1.1.0.Alpha1 (0) [ 192] [Active ] [ ] [ 80] JBoss Logging 3 (3.1.0.GA) [ 195] [Active ] [ ] [ 80] wrap_mvn_http___snapshots.jboss.org_maven2_org.hibernate.common_hibernate-commons-annotations_4.0.1-SNAPSHOT (0) [ 211] [Active ] [ ] [ 80] H2 Database Engine (1.3.170) [ 215] [Active ] [Created ] [ 80] Karaf Examples :: JPA :: DataSource (1.0.0.SNAPSHOT) [ 227] [Active ] [ ] [ 80] Servlet 3.0 (1.0) [ 228] [Active ] [ ] [ 80] hibernate-core (4.2.0.CR2) [ 229] [Active ] [ ] [ 80] hibernate-entitymanager (4.2.0.CR2) [ 230] [Active ] [ ] [ 80] hibernate-osgi (4.2.0.CR2) [ 231] [Active ] [Created ] [ 80] Karaf Examples :: JPA :: Utils (1.0.0.SNAPSHOT) [ 233] [Active ] [Created ] [ 80] Karaf Examples :: JPA :: Hibernate (1.0.0.SNAPSHOT)

And then when I try to run a little test that work with OpenJPA and Eclipselink I have an NPE exception:

java.lang.NullPointerException at org.apache.aries.jpa.container.impl.CountingEntityManagerFactory.createEntityManager(CountingEntityManagerFactory.java:65)[59:org.apache.aries.jpa.container:1.0.0] at Proxy735ba6d6_df91_4682_9974_d420f75b1cf1.createEntityManager(Unknown Source)[:] at lb.examples.karaf.jpa.hibernate.data.ApplicationManagedDataService.add(ApplicationManagedDataService.java:55)[233:jpa-hibernate:1.0.0.SNAPSHOT] at lb.examples.karaf.jpa.hibernate.cmd.ItemAddCommand.execute(ItemAddCommand.java:55)[233:jpa-hibernate:1.0.0.SNAPSHOT] at org.apache.felix.gogo.commands.basic.AbstractCommand.execute(AbstractCommand.java:35)[14:org.apache.karaf.shell.console:2.3.0] at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:78)[14:org.apache.karaf.shell.console:2.3.0] at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:474)[14:org.apache.karaf.shell.console:2.3.0] at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:400)[14:org.apache.karaf.shell.console:2.3.0] at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[14:org.apache.karaf.shell.console:2.3.0] at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)[14:org.apache.karaf.shell.console:2.3.0] at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)[14:org.apache.karaf.shell.console:2.3.0] at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:89)[14:org.apache.karaf.shell.console:2.3.0] at org.apache.karaf.shell.console.jline.Console.run(Console.java:175)[14:org.apache.karaf.shell.console:2.3.0] at java.lang.Thread.run(Thread.java:722)[:1.7.0_15]

I do not know if it is because of a misconfiguration in my sample or a bug:

OSGi Blueprint:

blueprint default-activation="eager"
           xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0"
           xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0">

    <bean id="app_managed_data_service"
          class="lb.examples.karaf.jpa.hibernate.data.ApplicationManagedDataService">
        <jpa:unit unitname="DATA_HIBERNATE" property="entityManagerFactory"/>
    </bean>

    <service ref="app_managed_data_service"
             interface="lb.examples.karaf.jpa.hibernate.data.IDataService">
        <service-properties>
            <entry key  ="osgi.jndi.service.name"
                   value="eclipselink/app_managed_data_service"/>
        </service-properties>
    </service>

    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
        <command name="item/add">
            <action class="lb.examples.karaf.jpa.hibernate.cmd.ItemAddCommand">
                <property name="applicationManagedDataService" ref="app_managed_data_service"/>
            </action>
        </command>
        <command name="item/list">
            <action class="lb.examples.karaf.jpa.hibernate.cmd.ItemListCommand">
                <property name="applicationManagedDataService" ref="app_managed_data_service"/>
            </action>
        </command>
    </command-bundle>

</blueprint>

Persistence.xml:

<persistence
    xsi:schemaLocation="
        http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    version="2.0">

    <persistence-unit name="DATA_HIBERNATE" transaction-type="RESOURCE_LOCAL">
        <!--
            Unfortunately Hibernate does not export the persistence provider class
            but the Activator class as it extends the HibernatePersistenceProvider:
            org.hibernate.jpa.HibernatePersistenceProvider

            Reference:
            repository: https://github.com/hibernate/hibernate-orm/b
            file      : hibernate-osgi/src/main/java/org/hibernate/osgi/HibernateBundleActivator.java
            jira      : https://hibernate.onjira.com/browse/HHH-8046
        -->
        <provider>org.hibernate.osgi.HibernateBundleActivator</provider>
        <non-jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/DS)</non-jta-data-source>
        <class>lb.examples.karaf.jpa.hibernate.data.Item</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
        </properties>
    </persistence-unit>

</persistence>
lgazo commented 11 years ago

the same is for Karaf 2.3.1

brmeyer commented 11 years ago

@lgazo , is your bundle in a public repo? I'd be happy to pull it down and debug a bit. Some extra use cases are always helpful.

lgazo commented 11 years ago

I've quickly copied sources here: https://github.com/lgazo/karaf-poc

Status:

fyi. I am quite new to osgi so some things might be set up incorrectly - I welcome any comments in this regard :)

lburgazzoli commented 11 years ago

I do not more have any NPE exception since the migration to 4.2.1-SNAPSHOT