War accessing a jar with JPA entities,Spring and persistence.xml in jboss-5.1.0.GA
chandan.ray Jan 5, 2014 1:34 PMHi,
I am creating a jar as DataLayerService.jar of one of my module - DataLayerService and putting it inside WEB-INF/lib directory of my application TestServiceLayer. Then I am deploying the war of TestServiceLayer namely - TestServiceLayer.war in jboss-5.1.0.GA.
Contents of my persistence.xml file -
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="bts-72">
<description>Bts</description>
<jta-data-source>java:BtsDS</jta-data-source>
<properties>
<property name="hibernate.show_sql" value="false"/>
<property name="jboss.as.jpa.providerModule" value="hibernate3-bundled"/>
<property name="javax.persistence.validation.mode">none</property>
</properties>
</persistence-unit>
</persistence>
and the location of persistence.xml file is -
DataLayerService
|
META-INF
|
persistence.xml
And Content fo my service-spring-config.xml -
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManagerName" value="java:/TransactionManager"/> </bean> -->
<tx:annotation-driven/>
<tx:jta-transaction-manager/>
<context:annotation-config/>
<!-- <bean class="com.gravitant.bms.billing.service.automation.BillImportService" id="billImportService" factory-method="getInstance"> </bean> -->
<!-- <bean class="com.gravitant.util.EntityManagerProxyImpl" id="entityManagerProxy"/> <bean class="com.gravitant.util.PlanningFindersUtil" id="findersUtil" factory-method="getInstance"> <property name="entityManagerProxy" ref="entityManagerProxy"/> </bean> -->
<!-- <bean class="com.gravitant.billing.BillDAOImpl" id="billDAO"> <property name="entityManagerProxy" ref="entityManagerProxy"/> <property name="findersUtil" ref="findersUtil"/> </bean> <bean class="com.gravitant.billing.BillService" id="billService"> <property name="billDAO" ref="billDAO"/> </bean> -->
</beans>
This service-spring-config.xml is located in the classpath of DataLayerService.jar
In the library of DataLayerService module I have included - ejb3-persistence.jar file.
I have used annotations @PersistenceContext to include the EntityManager -
@PersistenceContext
private EntityManager entityManager;
In the TestServiceLayer I have the following -
/WEB-INF/lib directory contains DataServiceLayer.jar.
In the classpath of TestServiceLayer, I have hibernate.properties and spring-config.xml file -
Content of hibernate.properties file -
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=true
hibernate.cache.region.factory_class=net.sf.ehcache.hibernate.EhCacheRegionFactory
hibernate.cache.provider_configuration_file_resource_path=ehcache.xml
hibernate.dialect=org.hibernate.dialect.MySQLDialect
Content of spring-config.xml file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<tx:annotation-driven/>
<tx:jta-transaction-manager/>
<context:annotation-config/>
<!-- <jee:jndi-lookup id="myEmf" jndi-name="persistence/myPersistenceUnit"/> -->
<!-- <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/> -->
<context:component-scan base-package="com.myapp"/>
<!-- <bean class="com.gravitant.rest.BillWebService" id="billWebService"> <property name="billService"> <ref bean="billService"/> </property> </bean> -->
</beans>
After creating the war file of TestServiceLayer application if I deploy it in the server, I get the following exception -
2014-01-05 23:06:18,579 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] (main) Error installing to Real: name=vfszip:/C:/jboss/jboss-5.1.0.GA/server/default/deploy/TestServiceLayer.war/ state=PreReal mode=Manual requiredState=Real
org.jboss.deployers.spi.DeploymentException: Error during deploy: org.jboss.metadata.jpa.spec.PersistenceUnitMetaData.bts-72
at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49)
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:177)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
at org.jboss.system.server.profileservice.repository.ProfileDeployAction.install(ProfileDeployAction.java:70)
at org.jboss.system.server.profileservice.repository.AbstractProfileAction.install(AbstractProfileAction.java:53)
at org.jboss.system.server.profileservice.repository.AbstractProfileService.install(AbstractProfileService.java:361)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
at org.jboss.system.server.profileservice.repository.AbstractProfileService.activateProfile(AbstractProfileService.java:306)
at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:271)
at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:461)
at org.jboss.Main.boot(Main.java:221)
at org.jboss.Main$1.run(Main.java:556)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at java.util.Hashtable.put(Unknown Source)
at java.util.Hashtable.putAll(Unknown Source)
at org.jboss.jpa.deployers.PersistenceUnitDeployer.addDependencies(PersistenceUnitDeployer.java:75)
at org.jboss.jpa.deployers.PersistenceUnitDeployer.deploy(PersistenceUnitDeployer.java:117)
at org.jboss.jpa.deployers.PersistenceUnitDeployer.deploy(PersistenceUnitDeployer.java:51)
at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
... 30 more
I am struggling a lot to overcome this exception.
May be someone can help me with some tips to overcome this exception.
Thanking in advance
Chandan