Search code examples
jbossosgijbossfusehibernate-enversblueprint-osgi

JBoss Fuse OSGi envers not working


I want to use hibernate envers auditing for generating aud tables and deploy it to Jboss fuse OSGi Karaf container. Added @Audited notation in entity class and hibernate-envers jar in my pom file.

Here is my pom.xml file,

<parent>
    <groupId>fuse-examples</groupId>
    <artifactId>fuse-spring-hibernate-module</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>


<artifactId>fuse-blueprint-hibernate</artifactId>
<packaging>bundle</packaging>

<name>Business Service</name>

<properties>
    <camel-version>1.5.0</camel-version>
    <maven-bundle-plugin>2.4.0</maven-bundle-plugin>
    <javax.persistence>2.0.0</javax.persistence>
</properties>

<dependencies>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>javax.persistence</artifactId>
        <version>${javax.persistence}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
    </dependency>
    <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-envers</artifactId>
     </dependency>
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-jpa_2.0_spec</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-jta_1.1_spec</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <defaultGoal>install</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.4.0</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>business-service</Bundle-SymbolicName>
                    <Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
                    <Import-Package>
                        org.hibernate.envers,
                        javax.sql,
                        javax.persistence,
                        org.hibernate.proxy,
                        javassist.util.proxy,
                        org.slf4j
                    </Import-Package>
                    <Include-Resource>src/main/resources</Include-Resource>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

If i removed org.hibernate.envers from pom.xml, the table got created but _aud tables not generated. What settings i missed? Anything settings missed in osgi container or pom.xml? Or anything want to setup in blueprint xml?

Help me.


Solution

  • After some researched did about JBoss Fuse Karaf based OSGi container, I completed the task. Actually we building the bundle for deploying it to OSGi container, we should set some settings. First of all we should tell what are the packages load by OSGi container and what are the packages by embedding into bundle. Bundle manifest file will define this. That is the root settings for every bundle. In hardcore frameworks or dependencies can embed within the bundle. My mistake was i just declared org.hibernate.envers for using hibernate envers.

                     <Import-Package>
                        org.hibernate.envers,
                        javax.sql,
                        javax.persistence,
                        org.hibernate.proxy,
                        javassist.util.proxy,
                        org.slf4j
                    </Import-Package>
    

    Most of times classloading issues may occur, If this occurs resources may null. The solution is we should import everything envers imports.

    Here i pasted my manifest file, It is working fine.

    Manifest-Version: 1.0
    Bnd-LastModified: 1481971039345
    Build-Jdk: 1.8.0_112
    Built-By: Smile
    Bundle-Activator: com.fuse.hibernate.services.OsgiBundleActiva
     tor
    Bundle-Blueprint: OSGI-INF/blueprint/blueprint.xml
    Bundle-ClassPath: .,hibernate-envers-4.2.22.Final-redhat-1.jar
    Bundle-ManifestVersion: 2
    Bundle-Name: FUSE-HIBERNATE
    Bundle-SymbolicName: fuse-hibernate
    Bundle-Version: 1.0.0.SNAPSHOT
    Created-By: Apache Maven Bundle Plugin
    Export-Package: <Exported Packages>
    Export-Service: com.fuse.repository.CustomRepository
    Import-Package: org.hibernate.annotations;version="[4.2,5)",org.hibernat
     e.annotations.common.reflection;version="[4.0,5)",javax.persistence;ver
     sion="[2.0,3)",org.hibernate.proxy;version="[4.2,5)",javassist.util.pro
     xy;version="[3.18,4)",org.slf4j;version="[1.7,2)",javax.management,java
     x.naming,javax.persistence.metamodel;version="[2.0,3)",javax.transactio
     n;version="[1.1,2)",org.apache.commons.beanutils;version="[1.8,2)",org.
     apache.commons.lang3;version="[3.0,4)",org.apache.tools.ant,org.dom4j,o
     rg.dom4j.io,org.dom4j.tree,org.hibernate;version="[4.2,5)",org.hibernat
     e.action.spi;version="[4.2,5)",org.hibernate.cache;version="[4.2,5)",or
     g.hibernate.cfg;version="[4.2,5)",org.hibernate.collection.spi;version=
     "[4.2,5)",org.hibernate.criterion;version="[4.2,5)",org.hibernate.diale
     ct;version="[4.2,5)",org.hibernate.engine.jdbc.spi;version="[4.2,5)",or
     g.hibernate.engine.loading.internal,org.hibernate.engine.spi;version="[
     4.2,5)",org.hibernate.engine.transaction.spi;version="[4.2,5)",org.hibe
     rnate.event.service.spi;version="[4.2,5)",org.hibernate.event.spi;versi
     on="[4.2,5)",org.hibernate.id;version="[4.2,5)",org.hibernate.id.enhanc
     ed;version="[4.2,5)",org.hibernate.integrator.spi;version="[4.2,5)",org
     .hibernate.internal,org.hibernate.internal.util;version="[4.2,5)",org.h
     ibernate.internal.util.collections,org.hibernate.internal.util.config,o
     rg.hibernate.internal.util.xml,org.hibernate.jdbc;version="[4.2,5)",org
     .hibernate.mapping;version="[4.2,5)",org.hibernate.metamodel.source;ver
     sion="[4.2,5)",org.hibernate.metamodel.spi;version="[4.2,5)",org.hibern
     ate.persister.collection;version="[4.2,5)",org.hibernate.persister.enti
     ty;version="[4.2,5)",org.hibernate.property;version="[4.2,5)",org.hiber
     nate.service;version="[4.2,5)",org.hibernate.service.classloading.spi;v
     ersion="[4.2,5)",org.hibernate.service.jdbc.dialect.internal,org.hibern
     ate.service.jndi;version="[4.2,5)",org.hibernate.service.spi;version="[
     4.2,5)",org.hibernate.sql;version="[4.2,5)",org.hibernate.tool.hbm2ddl;
     version="[4.2,5)",org.hibernate.type;version="[4.2,5)",org.hibernate.us
     ertype;version="[4.2,5)",org.jboss.logging;version="[3.1,4)",org.joda.t
     ime;version="[2.9,3)",org.osgi.framework;version="[1.6,2)",org.osgi.ser
     vice.blueprint;version="[1.0.0,2.0.0)",org.w3c.dom,javax.sql
    Meta-Persistence: META-INF/persistence.xml
    

    We can use Include-Resource tag for including hibernate as a resource and make sure to add this in bundle class path. It should work.