How do I exclude the JBoss provided javax.persistence module?
Asked Answered
C

4

9

I’m using JBoss 7.1.3.Final. I want to package my own Hibernate 4.3.0.Final Jars and the JPA 2.1 spec JARs within my WAR. It is not an option to replace the hibernate (or any other) module in JBoss.

How do I exclude the JPA 2.1 from my WAR?

I have tried placing this in my WEB-INF/jboss-deployment-structure.xml:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
    <deployment>
        <dependencies>
            <module name="org.codehaus.jackson.jackson-core-asl" />
            <module name="org.codehaus.jackson.jackson-mapper-asl" />
            <module name="org.slf4j" />
            <module name="com.mysql" />
            <module name="org.joda.time" />
            <module name="org.apache.velocity" />
            <module name="org.bouncycastle" slot="main" export="true" />
        </dependencies>
        <exclusions>
            <module name="org.apache.log4j" />
            <module name="org.hibernate" />
            <module name="javax.persistence" />
            <module name="javax.persistence.api" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

but somehow the JPA 2.1 gets loaded and my WAR deployment dies with this exception …

14:49:46,640 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ebook]] (MSC service thread 1-2) Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [META-INF/spring/infrastructure.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455) [spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) [spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) [spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) [spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) [spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) [spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) [spring-context-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:915) [spring-context-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472) [spring-context-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:388) [spring-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293) [spring-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) [spring-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.17.Final.jar:]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.17.Final.jar:]
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:89) [jboss-as-web-7.1.3.Final.jar:7.1.3.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) [classes.jar:    1.6.0_65]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) [classes.jar:1.6.0_65]
    at java.lang.Thread.run(Thread.java:695) [classes.jar:1.6.0_65]
Caused by: java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
    at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:936) [hibernate-core-4.3.0.Final.jar:4.3.0.Final]
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:781) [hibernate-core-4.3.0.Final.jar:4.3.0.Final]
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3762) [hibernate-core-4.3.0.Final.jar:4.3.0.Final]
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3716) [hibernate-core-4.3.0.Final.jar:4.3.0.Final]
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410) [hibernate-core-4.3.0.Final.jar:4.3.0.Final]
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844) [hibernate-core-4.3.0.Final.jar:4.3.0.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) [hibernate-entitymanager-4.3.0.Final.jar:4.3.0.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843) [hibernate-entitymanager-4.3.0.Final.jar:4.3.0.Final]
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399) [hibernate-core-4.3.0.Final.jar:4.3.0.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842) [hibernate-entitymanager-4.3.0.Final.jar:4.3.0.Final]
    at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:150) [hibernate-entitymanager-4.3.0.Final.jar:4.3.0.Final]
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:67) [hibernate-entitymanager-4.3.0.Final.jar:4.3.0.Final]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:287) [spring-orm-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310) [spring-orm-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514) [spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) [spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
    ... 20 more

These are my Maven decencies:

            <dependency>
                    <groupId>org.hibernate.javax.persistence</groupId>
                    <artifactId>hibernate-jpa-2.1-api</artifactId>
                    <version>1.0.0.Draft-16</version>
            </dependency>

            <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-validator</artifactId>
                    <version>4.3.0.Final</version>
                    <exclusions>
                            <exclusion>
                                    <groupId>org.slf4j</groupId>
                                    <artifactId>slf4j-api</artifactId>
                            </exclusion>
                    </exclusions>
            </dependency>
            <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-entitymanager</artifactId>
                    <version>4.3.0.Final</version>
            </dependency>

Any advice on how I can restructure my WAR is appreciated. I have verified no older version of the JPA 2.0 spec (through mvn dependency:tree) is getting loaded.

Edit:

Below is how I'm configuring my datasource in Spring. Note the absence of a persistence.xml file:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="packagesToScan" value="org.mainco.subco" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
    </property>
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaPropertyMap" ref="jpaPropertyMap" />
</bean>

<util:map id="jpaPropertyMap">
    <entry key="hibernate.show_sql" value="false" />
    <entry key="hibernate.hbm2ddl.auto" value="validate"/>
    <entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
    <entry key="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
    <entry key="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/>
    <entry key="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
    <entry key="hibernate.cache.use_second_level_cache" value="true" />
    <entry key="hibernate.cache.use_query_cache" value="false" />
    <entry key="hibernate.generate_statistics" value="false" />
</util:map>
Clothespress answered 14/5, 2014 at 19:58 Comment(5)
check the persistence.xml file. You can list your provider there <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> sets eclipse link as the provider.Handicap
Hi, I'm not using a persistence.xml file, instead, taking advantage of Spring's ability to autoscan packages. Given that, how would I attempt what you're suggesting?Clothespress
First "I want to package my own Hibernate 4.3.0.Final Jars and the JPA 2.1 spec JARs within my WAR" ... Then "How do I exclude the JPA 2.1 from my WAR? " which do you want?Matthei
you're excluding it in your jboss-deployment-structure, and including it in your maven... so you're going to have to change one of those...Matthei
Try to add another exclusion on module="org.jboss.as.jpa" into your jboss-deployment-structureLanate
B
6

If you are not able to exclude jboss provided module javax.persistence.api which i found in my jboss-eap-6.1 through WEB-INF/jboss-deployment-structure.xml in your war file, I suggest you to disable jpa extension module in standalone.xml or standalone-ha.xml which one you are using

<extension module="org.jboss.as.jmx"/>
<!--<extension module="org.jboss.as.jpa"/>   comment this one--> 
<extension module="org.jboss.as.jsf"/>
<extension module="org.jboss.as.logging"/>

Previously while we tried to integrate jersey-webservice in jboss server we got problem with jboss provided RESTEasy . Resteasy and JAX-RS are automically loaded into your deployment's classpath, if and only if you are deploying a JAX-RS Application.

So i was successful to integrate jersey webservice disabling following extension module in standalone.xml

<!--<extension module="org.jboss.as.jaxrs"/> -->

Once you start jboss server with commented extension module It will disappear from configuration file i.e standalone.xml. I would suggest you to give a try if jboss bundled library doesnot meet your requirement and you are not able to disable it from WEB-INF/jboss-deployment-structure.xml . Thanks.

Broach answered 23/5, 2014 at 0:30 Comment(2)
Sorry, the question was how can i do this all in my WAR file without having to modify the JBoss environment.Clothespress
have you tried excluding jpa subsystem from jboss-deployment-structure.xml.But i am not sure if it will work. ** <exclude-subsystems> <subsystem name="SUBSYSTEM_NAME" /> </exclude-subsystems> **Broach
T
3

Yes you can disable the extension by commenting it out, but also remove the following subsystem as follows from standalone.xml.

<!-- <subsystem xmlns="urn:jboss:domain:jpa:1.1">
    <jpa default-datasource="" default-extended-persistence-inheritance="DEEP"/>
</subsystem> -->
Tattle answered 23/5, 2014 at 18:54 Comment(1)
I did this too but after doing that I get errors on JBPM. It seems JBoss uses its own JPA lo load JBPM for its internal processesMuco
T
0

You can also solve the issue simply by replacing the JPA api jar file which is located at jboss7/modules/javax/persistence/api/main with 'hibernate-jpa-2.1-api' also with updating module.xml in the directory with the 2.1 api file name.

Tetany answered 24/1, 2015 at 14:25 Comment(0)
A
-1

Replacing with hibernate-jpa-2.1-api - Worked perfectly.

Antitype answered 13/1, 2016 at 13:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.