无法将WAR文件从Tomcat移植到Glassfish。资源_LOCAL与JTA之间的错误
我正试图发动一场战争,在Tomcat上部署并运行良好,然后在Glassfish上部署。Glassfish中的初始错误消息为: com.sun.enterprise.deployment.backend.IASDeploymentException: 部署错误--错误 持久性上下文引用名称 [org.nhindirect.config.store.dao.impl.anchordaimpl/entityManager] 模块内 [C:\Sun\AppServer\domains\domain1\applications\j2ee模块\config服务] 解析为一个名为 [config store]的类型 本地资源。只有持久性单位 对于事务类型,可以使用JTA 作为容器管理的实体管理器。 请验证您的申请 WAR的META-INF文件夹中没有persistence.xml。但是,WEB-INF\lib下有一个JAR,它本身包含persistence.xml。其内容如下:无法将WAR文件从Tomcat移植到Glassfish。资源_LOCAL与JTA之间的错误,glassfish,jta,Glassfish,Jta,我正试图发动一场战争,在Tomcat上部署并运行良好,然后在Glassfish上部署。Glassfish中的初始错误消息为: com.sun.enterprise.deployment.backend.IASDeploymentException: 部署错误--错误 持久性上下文引用名称 [org.nhindirect.config.store.dao.impl.anchordaimpl/entityManager] 模块内 [C:\Sun\AppServer\domains\domain1\a
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="config-store" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.hbm2ddl.auto" value="validate" />
</properties>
</persistence-unit>
</persistence>
如果有帮助,下面是WAR的beans.xml的内容:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"
default-autowire="byName">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<context:annotation-config />
<context:component-scan base-package="org.nhindirect.config" />
<tx:annotation-driven transaction-manager="transactionManager" />
<jaxws:endpoint id="configurationService"
address="/ConfigurationService" >
<jaxws:implementor>
<bean id="configurationServiceImpl"
class="org.nhindirect.config.service.impl.ConfigurationServiceImpl">
<property name="domainSvc" ref="domainSvc"/>
<property name="addressSvc" ref="addressSvc"/>
<property name="anchorSvc" ref="anchorSvc"/>
<property name="certSvc" ref="certSvc"/>
<property name="settingSvc" ref="settingSvc"/>
<property name="DNSSvc" ref="dnsSvc"/>
</bean>
</jaxws:implementor>
</jaxws:endpoint>
<!-- <jaxws:endpoint id="addressService" implementor="org.nhindirect.config.service.ws.AddressServiceWS"
address="/AddressService" /> -->
<!-- Service Implementations -->
<bean id="domainSvc" class="org.nhindirect.config.service.impl.DomainServiceImpl">
<property name="dao" ref="domainDao"/>
</bean>
<bean id="addressSvc" class="org.nhindirect.config.service.impl.AddressServiceImpl">
<property name="dao" ref="addressDao"/>
</bean>
<bean id="anchorSvc" class="org.nhindirect.config.service.impl.AnchorServiceImpl">
<property name="dao" ref="anchorDao"/>
</bean>
<bean id="certSvc" class="org.nhindirect.config.service.impl.CertificateServiceImpl">
<property name="dao" ref="certificateDao"/>
</bean>
<bean id="settingSvc" class="org.nhindirect.config.service.impl.SettingServiceImpl">
<property name="dao" ref="settingDao"/>
</bean>
<bean id="dnsSvc" class="org.nhindirect.config.service.impl.DNSServiceImpl">
<property name="dao" ref="dnsDao"/>
</bean>
<!-- DAO's -->
<bean id="domainDao" class="org.nhindirect.config.store.dao.impl.DomainDaoImpl"/>
<bean id="addressDao" class="org.nhindirect.config.store.dao.impl.AddressDaoImpl"/>
<bean id="anchorDao" class="org.nhindirect.config.store.dao.impl.AnchorDaoImpl" />
<bean id="certificateDao" class="org.nhindirect.config.store.dao.impl.CertificateDaoImpl"/>
<bean id="settingDao" class="org.nhindirect.config.store.dao.impl.SettingDaoImpl"/>
<bean id="dnsDao" class="org.nhindirect.config.store.dao.impl.DNSDaoImpl"/>
<!-- Exception translation bean post processor -->
<bean
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<!-- SWAP THIS JPA IMPLEMENTATION WITH THE APPROPROATE DB CONFIGURATION
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" />
</bean>
</property>
<property name="persistenceUnitName" value="config-store" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql:nhindconfig" />
<property name="username" value="nhind" />
<property name="password" value="nhind" />
</bean>
-->
<!-- EMBEDDED DERBY JPA CONFIGURATION FOR A WORKING OUT OF THE BOX CONFIGURATION WITH NO PREREQUISITES OF
SETTING UP AN EXTERNAL DATABASE. REMOVE THIS SECTION AND REPLACE WITH READ JPA CONFIGURATION (SEE
ABOVE SECTION) FOR PRODUCTION -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
<!-- <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" /> -->
<property name="databasePlatform" value="org.hibernate.dialect.DerbyDialect" />
</bean>
</property>
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="config-store" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="url" value="jdbc:derby:nhindconfig;create=true" />
<property name="username" value="nhind" />
<property name="password" value="nhind" />
</bean>
<!-- END DERBY JPA CONFIGURATION -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" />
</beans>
对不起,我提供的信息太多了。我是JPA的新手,不确定什么对任何人都有帮助,什么对任何人都没有帮助
提前感谢您。在您的代码中的某个地方,您可能正在注入一个
EntityManager
,使用的代码如下所示:
@PersistanceContext // Requires JTA
EntityManager em;
在这种情况下,您要求容器(Glassfish本身)为您创建和管理EntityManager
。Glassfish是可群集的,它试图防止您意外地跨多个服务器进行事务,而这不是真正的ACID,但要求您使用JTA事务(可在多个群集服务器之间共享)
如果您确信永远不会为此应用程序群集glassfish容器,则可以安全地继续使用RESOURCE_本地事务,但是,您不能让glassfish为您管理EntityManager
。不过,您可以让glassfish管理EntityManager工厂
@PersistanceUnit // Does NOT require JTA
EntityManagerFactory factory;
这对于资源本地的持久性单元是安全的。您只需要使用factory.createEntityManager()
从工厂请求EntityManager
现在您的EntityManager是应用程序管理的,而不是容器管理的。因此Glassfish将假定您将在集群中处理事务隔离
@PersistanceUnit // Does NOT require JTA
EntityManagerFactory factory;