How can I exclude javax.persistence javoss module?

Im using JBoss 7.1.3.Final. I want to pack my own Hibernate 4.3.0.Final Jars and JPA 2.1 spec JAR in my WAR. This is not an option to replace a sleeping (or any other) module in JBoss.

How to exclude JPA 2.1 from my WAR?

I 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 JPA 2.1 boots up 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 tricks:

  <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 welcome. I checked that an older version of the JPA 2.0 specification (via mvn dependency: tree) is not loading.

Edit:

The following describes how I configure my data source in Spring. Note the missing 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> 
+8
module hibernate jboss
source share
4 answers

If you cannot exclude the javax.persistence.api module provided by jboss , which I found in my jboss-eap-6.1 via WEB-INF / jboss-deployment-structure.xml in your war file, I suggest that you disable the jpa extension module in standalone .xml or stand-alone-ha.xml that you use

 <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"/> 

Earlier, when we tried to integrate the jersey-webservice on the jboss server, we had a problem with the provided jboss RESTEasy , Restaasy and JAX-RS are automatically loaded into your deployment class path if and only if you deploy the JAX-RS application.

So, I managed to integrate the jersey webservice to disable the next extension module in standalone.xml

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

As soon as you start the jboss server with the comment of the extension module, it will disappear from the ie standalone.xml configuration file. I would suggest to try if the jboss library in the kit does not meet your requirement and you cannot disconnect from WEB -INF / jboss-deployment-structure.xml . Thanks.

+5
source share

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

 <!-- <subsystem xmlns="urn:jboss:domain:jpa:1.1"> <jpa default-datasource="" default-extended-persistence-inheritance="DEEP"/> </subsystem> --> 
+2
source share

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

0
source share

Replacing sleep mode-jpa-2.1-api - works great.

-one
source share

All Articles