所以我使用JPA(OpenJPA 2.3.0实现)可能是一种非常规的方式。我正在编写一个软件来维护一些人员数据并将工作分配给所述人员。它分配的工作类型是未定义的 - 用户必须扩展映射的超类,为该类添加任何其他映射,我的软件基本上将从那里获取它。我们有几个遵循这种模式的系统,我们只想编写一次赋值代码。但是,分配的内容存在细微差别 - 某些系统分配案例,其他分配案例的较小部分,其他分配基于客户等等。
为了获得最大的可配置性,我将持久化实体的所有元数据放入映射文件中,而不是使用注释。由于使用我的软件的程序员必须扩展该映射的超类并将它们自己的映射添加到持久性单元,所以我不想将persistence.xml或我的映射XML打包到我正在创建的jar中。我认为程序员可以在他们耳边的某个地方包含这些文件。我使用Java SE而不是EE编写了整个内容,所以我自己创建了EntityManagerFactory而不是注入它。
我的组织正在使用实现Java EE 5的Websphere Application Server 7.0。在Java EE 5中查看JPA的文档,我的用户似乎必须打包persistence.xml并将XML文件映射到一个单独的jar中被放在耳朵的图书馆文件夹中。然后他们可以在persistence.xml中引用我的jar文件。类似下面的内容(我的软件名称是WAM):
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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_2_0.xsd">
<persistence-unit name="WAM" transaction-type="RESOURCE_LOCAL">
<mapping-file>wamMapping.xml</mapping-file>
<jar-file>wam-1.0.0.jar</jar-file>
</persistence-unit>
我试图以这种方式编写一个快速而脏的Web服务。我添加了我的persistence.xml文件并将XML映射到名为wam-config.jar的jar并将其粘贴到ear library文件夹中。当我发出Web服务请求时,我收到以下错误:
javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "WAM" after trying the following discovered implementations: com.ibm.websphere.persistence.PersistenceProviderImpl, org.apache.openjpa.persistence.PersistenceProviderImpl, org.apache.openjpa.persistence.PersistenceProviderImpl, org.apache.openjpa.persistence.PersistenceProviderImpl with the following failures:
com.ibm.websphere.persistence.PersistenceProviderImpl returned: java.lang.IllegalArgumentException: The jar resource "wam-1.0.0.jar" cannot be loaded.
at org.apache.openjpa.persistence.PersistenceUnitInfoImpl.validateJarFileName(PersistenceUnitInfoImpl.java:277)
at org.apache.openjpa.persistence.PersistenceUnitInfoImpl.processJarFileNames(PersistenceUnitInfoImpl.java:239)
at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:538)
at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:335)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:89)
at com.ibm.websphere.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:73)
at com.ibm.websphere.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:43)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:154)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:65)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:150)
at gov.ssa.wam.service.BaseWAMService.initializeEntityManagerFactory(BaseWAMService.java:73)
at gov.ssa.wam.service.BaseWAMService.<init>(BaseWAMService.java:34)
at gov.ssa.wam.service.WAMServiceDelegate.getInstance(WAMServiceDelegate.java:31)
at gov.ssa.earnings.webservice.WAMServiceBean.<init>(WAMServiceBean.java:22)
at java.lang.J9VMInternals.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1474)
at com.ibm.wsspi.injectionengine.InjectionUtil.createInjectedInstance(InjectionUtil.java:79)
at com.ibm.ws.websvcs.server.WSServiceInstanceFactory.createServiceInstance(WSServiceInstanceFactory.java:110)
at org.apache.axis2.jaxws.server.EndpointController.handleRequest(EndpointController.java:247)
at org.apache.axis2.jaxws.server.EndpointController.invoke(EndpointController.java:103)
at org.apache.axis2.jaxws.server.JAXWSMessageReceiver.receive(JAXWSMessageReceiver.java:161)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:189)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
at com.ibm.ws.websvcs.transport.http.WASAxis2Servlet.doPost(WASAxis2Servlet.java:1431)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1663)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:939)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:181)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:864)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1592)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1646)
org.apache.openjpa.persistence.PersistenceProviderImpl returned: java.lang.IllegalArgumentException: The jar resource "wam-1.0.0.jar" cannot be loaded.
at org.apache.openjpa.persistence.PersistenceUnitInfoImpl.validateJarFileName(PersistenceUnitInfoImpl.java:277)
at org.apache.openjpa.persistence.PersistenceUnitInfoImpl.processJarFileNames(PersistenceUnitInfoImpl.java:239)
at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:538)
at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:335)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:89)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:154)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:65)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:150)
at gov.ssa.wam.service.BaseWAMService.initializeEntityManagerFactory(BaseWAMService.java:73)
at gov.ssa.wam.service.BaseWAMService.<init>(BaseWAMService.java:34)
at gov.ssa.wam.service.WAMServiceDelegate.getInstance(WAMServiceDelegate.java:31)
at gov.ssa.earnings.webservice.WAMServiceBean.<init>(WAMServiceBean.java:22)
at java.lang.J9VMInternals.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1474)
at com.ibm.wsspi.injectionengine.InjectionUtil.createInjectedInstance(InjectionUtil.java:79)
at com.ibm.ws.websvcs.server.WSServiceInstanceFactory.createServiceInstance(WSServiceInstanceFactory.java:110)
at org.apache.axis2.jaxws.server.EndpointController.handleRequest(EndpointController.java:247)
at org.apache.axis2.jaxws.server.EndpointController.invoke(EndpointController.java:103)
at org.apache.axis2.jaxws.server.JAXWSMessageReceiver.receive(JAXWSMessageReceiver.java:161)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:189)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
at com.ibm.ws.websvcs.transport.http.WASAxis2Servlet.doPost(WASAxis2Servlet.java:1431)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1663)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:939)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:181)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:864)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1592)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1646)
wam-1.0.0.jar文件位于ear library文件夹中。它似乎是在wam-config.jar中找到persistence.xml,但它找不到(或不能使用)wam-1.0.0.jar。任何人都知道我哪里出错了?
编辑:根据请求发布完整的堆栈跟踪。对不起!
答案 0 :(得分:0)
我明白了。它似乎无法找到我的映射XML文件。
我开始通过做事经历实验&#34;经典&#34;方式 - 包括我的持久化实体在jar中的persistence.xml和我的映射XML文件。这也不起作用。然后,我将persistence.xml中的映射文件的路径更改为&#34; META-INF / wamMapping.xml&#34;事情开始奏效了!之后,我从jar文件中删除了persistence.xml和映射XML,并将它们放在META-INF目录中的单独jar文件中。然后我把它放在我的耳库里。还在工作!
我现在无法让我的战争中的其他持久类正常工作,但这是一个不同的问题。