OSGi Hibernate envers Support - osgi

I'm stuck in osgi envers support integrating in my bundle. I'm using hibernate-core and hibernate envers 4.2.22 redhat version, how to implement this in blueprint?
I have entities with #Audited annotations and importing org.hibernate.envers packages.
I want to use auditing and revisions.

See Chapter 17.7 of the hibernate docs.
You register the envers extension as an OSGi service.
<blueprint default-activation="eager">
<bean id="integrator" class="org.hibernate.envers.event.spi.EnversIntegrator" />
<service ref="integrator" interface="org.hibernate.integrator.spi.Integrator" />
</blueprint>

After registered envers extension service, imported needed envers supported packages in my manifest.
The required packages should be imported via Embed dependency method. Used Include-Resource tag for including hibernate resource and make sure add Bundle-Classpath for defining envers dependency. Now it is working fine in JBoss fuse karaf based OSGi container then revinfo and _aud tables got created successfully.
Here is my Manifest,
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

Related

AEM OSGI Bundle for MSSQL - error javax.net.SocketFactory classdefnotfound

I am trying to create an OSGI bundle for MSSQL driver. I'll post my Manifest below.
Basically, I get an error javax.net.SocketFactory no class def found.
I am able to upload the bundle and start it but, fails when trying to use the a datasource.
Here is my manifest:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Jdbc
Bundle-SymbolicName: com.s360g.mssql.jdbc
Bundle-Version: 1.0.0
Automatic-Module-Name: com.s360g.mssql.jdbc
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: com.microsoft.sqlserver.jdbc,
microsoft.sql
Import-Package: javax.naming,
javax.naming.spi,
javax.net,
javax.net.ssl,
javax.security.auth,
javax.security.auth.login,
javax.security.auth.x500,
javax.sql,
javax.transaction.xa,
javax.xml.parsers,
javax.xml.stream,
javax.xml.transform,
javax.xml.transform.dom,
javax.xml.transform.sax,
javax.xml.transform.stax,
javax.xml.transform.stream,
org.ietf.jgss,
org.w3c.dom,
org.xml.sax,
org.xml.sax.helpers
com.adobe.granite.workflow.WorkflowException: Process execution resulted in an error
at com.adobe.granite.workflow.core.job.HandlerBase.executeProcess(HandlerBase.java:201) [com.adobe.granite.workflow.core:2.0.240.CQ650-B0016]
at com.adobe.granite.workflow.core.job.JobHandler.process(JobHandler.java:260) [com.adobe.granite.workflow.core:2.0.240.CQ650-B0016]
at org.apache.sling.event.impl.jobs.JobConsumerManager$JobConsumerWrapper.process(JobConsumerManager.java:502) [org.apache.sling.event:4.2.12]
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.startJob(JobQueueImpl.java:293) [org.apache.sling.event:4.2.12]
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.access$100(JobQueueImpl.java:60) [org.apache.sling.event:4.2.12]
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl$1.run(JobQueueImpl.java:229) [org.apache.sling.event:4.2.12]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NoClassDefFoundError: javax/net/SocketFactory
at com.microsoft.sqlserver.jdbc.SocketFinder.getSocketFactory(IOBuffer.java:2636)
at com.microsoft.sqlserver.jdbc.SocketFinder.getConnectedSocket(IOBuffer.java:2687)
at com.microsoft.sqlserver.jdbc.SocketFinder.getDefaultSocket(IOBuffer.java:2674)
at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2358)
at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:672)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2747)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2418)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:2265)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1291)[!
Bundle information]1
Help is appreciated.

Hibernate (4.3.11-Final) logging not bridging to log4j2?

We are migrating from log4j to log4j2. We use the following libraries and there logging mechanisms:
Tomcat (which uses JULI), Spring 4.2.0 (which uses commons-logging) and Hibernate 4.3.11-Final (which uses jboss-logging).
I have successfully got Spring bridging to log4j2, but Hibernate logging is not working.
According to the Hibernate docs:
To use JBoss Logging with Log4j2, the log4j2 jar would also need to be available on the classpath.
I have the following logging-related jars on my classpath:
commons-logging-1.2.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
log4j-api-2.6.1.jar
log4j-core-2.6.1.jar
log4j-jcl-2.6.1.jar
log4j-slf4j-impl-2.6.1.jar
slf4j-api-1.7.5.jar
slf4j-log4j12-1.7.5.jar
Any ideas why I'm not seeing the results I expect?
The version of jboss-logging included with hibernate-4 is not compatible with log4j2.
I had to import version 3.3.0.Final (should work starting with 3.1.4, according to JBLOGGING-94) for hibernate to work with log4j2.
Here is a shortcut if you use maven :
<dependency> <!-- version working with log4j2 -->
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.3.0.Final</version>
<scope>runtime</scope>
</dependency>

PropertiesLauncher unable to jar files in Uberjar when using Spring Boot

We seem to be having an issue while using propertiesLauncher (layout as ZIP). When we run the jar with or without using -Dloader.path
java -jar myuberjar.jar
We keep getting an error saying that it is not able to find jar file that is present in myuberjar.jar
Caused by: java.lang.IllegalArgumentException: File [/Users/myuser/myuberjar.jar!/lib/jackson-module-jaxb-annotations-2.5.4.jar] referenced by given URL [file:/Users/myuser/myuberjar.jar!/lib/jackson-module-jaxb-annotations-2.5.4.jar] does not exist
at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:73)
at org.hibernate.jpa.boot.archive.internal.JarProtocolArchiveDescriptor.<init>(JarProtocolArchiveDescriptor.java:71)
at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:55)
at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:48)
at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.buildArchiveDescriptor(AbstractScannerImpl.java:95)
at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:70)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.scan(EntityManagerFactoryBuilderImpl.java:725)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:221)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:188)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider$1.<init>(SpringHibernateJpaPersistenceProvider.java:49)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:49)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
Not sure what we are missing.
SpringBoot - 1.2.4.RELEASE
JDK1.8
PropertiesLauncher
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
</configuration>
</plugin>
When i extract the uberjar , i can see all the jars in the lib folder. Bellow are the contents of the manifest file
Manifest-Version: 1.0
Implementation-Title: AppService
Implementation-Version: 0.0.1-SNAPSHOT
Archiver-Version: Plexus Archiver
Built-By: avinash
Start-Class: com.company.app.AppServiceApplication
Implementation-Vendor-Id: com.company.services.app
Spring-Boot-Version: 1.2.4.RELEASE
Created-By: Apache Maven 3.2.1
Build-Jdk: 1.8.0_25
Implementation-Vendor: Pivotal Software, Inc.
Main-Class: org.springframework.boot.loader.PropertiesLauncher
The issue is not with Spring Boot properties launcher, but more with Hibernate jars as described in the bug below.
https://hibernate.atlassian.net/browse/HHH-4161

ClassCastException: Can't cast oracle.sql.ARRAY to oracle.sql.ARRAY in JBoss 7.1.1.Final

DemoApp is spring integration project deployed in jboss 7.1.1.Final
The result returned from a stored procedure contains object of oracle.sql.ARRAY (object referring ojdbc jar of jboss module)
And I tried converting to oracle.sql.ARRAY which throwing exception
Code:
URL resultJarLocation= resultMap.get("returnObj").getClass().getProtectionDomain().getCodeSource().getLocation();
URL appJarLocation = oracle.sql.ARRAY.class.getProtectionDomain().getCodeSource().getLocation();
System.out.println("resultJarLocation : " + resultJarLocation);
System.out.println("appJarLocation : " + appJarLocation);
oracle.sql.ARRAY returnObj=(oracle.sql.ARRAY)resultMap.get("returnObj");
EXCEPTION:
org.springframework.messaging.MessageHandlingException: java.lang.ClassCastException: oracle.sql.ARRAY cannot be cast to oracle.sql.ARRAY
The application ARRAY class is referring ojdbc jar in the deployed application.
where as result set ARRAY class referreing ojdbc jar jboss module
Sys Output:
resultJarLocation : jar:file:/<JBOSS_HOME>/modules/com/oracle/ojdbc6/main/ojdbc6.jar
appJarLocation : vfs:/<JBOSS_HOME>/bin/content/DemoApp.war/WEB-INF/lib/ojdbc6.jar
You are trying to cast between classes loaded by different classloaders. JVM distinguishes classes not only by name and package but also by the classloader used. In other words, from JVM perspective is like trying to cast from say String to Long; you cannot.
The only think you can do is configuration. Set up either for the same classloader to be used, or the classloaders to be in the same hierarchy, to take advantage of delegation.
I am not very familiar with JBoss (especially current versions) but I know it has (or used to have in the past) some very different classloading strategy than other application servers. Checking with its documentation on classloading would be my first option.
I solved the problem by changing the ojdbc jar's scope as 'provided' as this will not include the jar in the WEB-INF/lib.
And then added the Dependencic of jboss 7 module 'com.oracle.ojdbc6' in pom.. which will add the Dependencies attribute in META-INF/MANIFEST.MF file, as a result on deployment the jboss 7's ojdbc jar will be uses for object creation for both jboss and application, and the classloader will be the jboss's classloader.
Bellow are the code in pom.
1) Manifest entry :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Dependencies>com.oracle.ojdbc6</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
2) Dependency as Provided:
<dependency>
<scope>provided</scope>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.2.0</version>
</dependency>
META-INF/Manifest.MF file will be generated with dependency entry
Manifest-Version: 1.0
Dependencies: com.oracle.ojdbc6
Built-By: Mrinmoy
Build-Jdk: 1.7.0_65
Created-By: Apache Maven 3.2.2
Archiver-Version: Plexus Archiver

Configuring Spring Batch with Maven

Configuring Spring Batch with Maven. JDK used: 1.6, Spring Batch version 2.1.8.RELEASE; Spring version 3.0.5.RELEASE. Getting run time exception as below:
D:\SpringProject\SpringTry\target>java -jar SpringTry-1.0-SNAPSHOT.jar jobs/helloWorld.xml helloWorldJob
2012-09-02 00:23:51,650 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - <Refreshing org.springframework.context.
support.ClassPathXmlApplicationContext#b29c9d: startup date [Sun Sep 02 00:23:51 IST 2012]; root of context hierarchy>
2012-09-02 00:23:51,769 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path
resource [jobs/helloWorld.xml]>
2012-09-02 00:23:53,854 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path
resource [launch-context.xml]>
2012-09-02 00:23:53,929 ERROR [org.springframework.batch.core.launch.support.CommandLineJobRunner] - <Job Terminated in error: Configuration
problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/batch]
Offending resource: class path resource [jobs/helloWorld.xml]
>
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler fo
r XML schema namespace [http://www.springframework.org/schema/batch]
Offending resource: class path resource [jobs/helloWorld.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
Any suggestion on how to resolve this. Also noticed that Spring 2.5.6 is getting downloaded everytime, along with version mentioned 3.0.5
My manifest looks like:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Build-Jdk: 1.6.0
Main-Class: org.springframework.batch.core.launch.support.CommandLineJobRunner
Class-Path: lib/spring-batch-core-2.1.9.RELEASE.jar lib/xstream-1.3.jar lib/xpp3_min-1.1.4c.jar lib/jettison-1.1.jar lib/spring-aop-2.5.6.jar lib/aopalliance-1.0.jar lib/spring-tx-2.5.6.jar lib/spring-batch-infrastructure-2.1.9.RELEASE.jar lib/spring-beans-3.0.5.RELEASE.jar lib/spring-context-3.0.5.RELEASE.jar lib/spring-expression-3.0.5.RELEASE.jar lib/spring-asm-3.0.5.RELEASE.jar lib/spring-core-3.0.5.RELEASE.jar lib/commons-logging-1.1.1.jar lib/spring-jdbc-3.0.5.RELEASE.jar lib/log4j-1.2.16.jar lib/maven-resources-plugin-2.4.3.jar lib/maven-plugin-api-2.0.6.jar lib/maven-project-2.0.6.jar lib/maven-profile-2.0.6.jar lib/maven-artifact-manager-2.0.6.jar lib/maven-plugin-registry-2.0.6.jar lib/maven-core-2.0.6.jar lib/wagon-file-1.0-beta-2.jar lib/maven-plugin-parameter-documenter-2.0.6.jar lib/wagon-http-lightweight-1.0-beta-2.jar lib/wagon-http-shared-1.0-beta-2.jar lib/jtidy-4aug2000r7-dev.jar lib/xml-apis-1.0.b2.jar lib/maven-reporting-api-2.0.6.jar lib/doxia-sink-api-1.0-alpha-7.jar lib/wagon-provider-api-1.0-beta-2.jar lib/maven-repository-metadata-2.0.6.jar lib/maven-error-diagnostics-2.0.6.jar lib/commons-cli-1.0.jar lib/wagon-ssh-external-1.0-beta-2.jar lib/wagon-ssh-common-1.0-beta-2.jar lib/maven-plugin-descriptor-2.0.6.jar lib/plexus-interactivity-api-1.0-alpha-4.jar lib/wagon-ssh-1.0-beta-2.jar lib/jsch-0.1.27.jar lib/classworlds-1.1.jar lib/maven-artifact-2.0.6.jar lib/maven-settings-2.0.6.jar lib/maven-model-2.0.6.jar lib/maven-monitor-2.0.6.jar lib/plexus-container-default-1.0-alpha-9-stable-1.jar lib/junit-3.8.1.jar lib/plexus-utils-2.0.5.jar lib/maven-filtering-1.0-beta-4.jar lib/plexus-build-api-0.0.4.jar lib/plexus-interpolation-1.13.jar
Most probably you are either:
simply using a version of spring-batch-core jar (Maven dependency) which has version below 2.0. Schema naming works for version 2.0 and above. If it's the case, update your dependency
or
You have the correct (higher than 2.0) version of spring-batch-core in your project's pom.xml, but you also have a transitive dependency which brings into your project an earlier version of spring-batch-core. If that's the case, try the following:
mvn dependency:tree -Dverbose -Dincludes=org.springframework.batch
this will list all the dependencies that bring in their own version of spring-batch dependencies. Add an exclude entry on spring-batch-core for those dependencies, something like this:
<dependency>
<groupId>whatever.group</groupId>
<artifactId>whateverArtifact</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
</exclusion>
</exclusions>
</dependency>
My issue was resolved by adding maven-shade-plugin as detailed in the:
https://stackoverflow.com/a/8574629/1419116

Resources