2014-09-10 78 views
0

所以我使用的JPA(OpenJPA 2.3.0實現)可能是一種非常規的方式。我正在編寫一個軟件,用於維護一些人員數據並將工作分配給所述人員。它指定什麼類型的工作是未定義的 - 用戶必須擴展一個映射的超類,爲該類添加任何額外的映射,並且我的軟件基本上會從那裏獲取它。我們有幾個遵循這種模式的系統,我們只想寫一次賦值代碼。但是,分配的內容有些許差異 - 某些系統分配了一個案例,其他分配了一個較小的案例,其他分配了一個客戶等。使用OpenJPA打包jar之外的persistence.xml

爲了獲得最大的可配置性,我將所有元數據我的持久化實體放入映射文件中,而不是使用註釋。由於使用我的軟件的程序員必須擴展映射的超類並將其自己的映射添加到持久單元,因此我不想將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庫文件夾中。當我提出Web服務請求時,我收到以下錯誤消息:

javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for &quot;WAM&quot; 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 &quot;wam-1.0.0.jar&quot; 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.&lt;init&gt;(BaseWAMService.java:34) 
at gov.ssa.wam.service.WAMServiceDelegate.getInstance(WAMServiceDelegate.java:31) 
at gov.ssa.earnings.webservice.WAMServiceBean.&lt;init&gt;(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 &quot;wam-1.0.0.jar&quot; 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.&lt;init&gt;(BaseWAMService.java:34) 
at gov.ssa.wam.service.WAMServiceDelegate.getInstance(WAMServiceDelegate.java:31) 
at gov.ssa.earnings.webservice.WAMServiceBean.&lt;init&gt;(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庫文件夾中。它似乎是在wam-config.jar中找到persistence.xml,但它找不到(或不能使用)wam-1.0.0.jar。任何人有任何想法我要去哪裏錯了?

編輯:每個請求發佈完整的堆棧跟蹤。對於那個很抱歉!

+0

是_COMPLETE_堆棧跟蹤?如果沒有,發佈它。 – 2014-09-10 15:39:29

回答

0

我想通了。它似乎無法找到我的映射XML文件。

我開始嘗試通過做一些「經典」的方式 - 包括jar中的persistence.xml和我的映射XML文件與持久實體。那也不管用。然後,我將persistence.xml中映射文件的路徑更改爲「META-INF/wamMapping.xml」,並開始工作!之後,我從我的jar文件中刪除了persistence.xml和我的映射XML,並將它們放在META-INF目錄內的單獨的jar文件中。然後我把它放在我的耳庫裏。還在工作!

我現在無法讓我的戰爭中的額外持久類正常工作,但這是一個不同的問題。

相關問題