2012-04-20 107 views
4

我正在運行一個使用EclipseLink的Web服務,它的效果很好。但有時候我會得到一個異常,提示「無法預先部署PersistenceUnit」。我不知道爲什麼我得到這個。其他一切似乎都起作用,並且這個例外似乎不會影響應用程序,它只是被捉住了。我得到一個PersistenceException,我不明白爲什麼

Exception Description: Unable to predeploy PersistenceUnit [MyLibPU] in invalid state [Undeployed] 
javax.persistence.PersistenceException: Exception [EclipseLink-28017] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.EntityManagerSetupException 
Exception Description: Unable to predeploy PersistenceUnit [MyLibPU] in invalid state [Undeployed] 
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:956) 
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:121) 
    at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source) 
    at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source) 
.... 
.... 
Caused by: Exception [EclipseLink-28017] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.EntityManagerSetupException 
Exception Description: Unable to predeploy PersistenceUnit [MyLibPU] in invalid state [Undeployed] 
    at org.eclipse.persistence.exceptions.EntityManagerSetupException.cannotPredeploy(EntityManagerSetupException.java:202) 
    ... 30 more 

在例外,我能找到一絲線的方法:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("MyLibPU"); 

爲什麼會出現呢?

編輯
這是輸出時的EclipseLink日誌記錄設置爲FINEST我得到。

[EL Finest]: 2012-04-23 15:19:06.025--ServerSession(2134178364)--Thread(Thread[Finalizer,8,system])--End undeploying Persistence Unit MyLibPU; session file:/home/Rox/MyLib/trunk/MyLib/build/classes/_MyLibPU; state Undeployed; factoryCount 0 
[EL Finest]: 2012-04-23 15:19:06.025--ServerSession(2113649746)--Thread(Thread[Finalizer,8,system])--Begin undeploying Persistence Unit MyLibPU; session file:/home/Rox/MyLib/trunk/MyLib/src/_MyLibPU; state Deployed; factoryCount 3 
[EL Finest]: 2012-04-23 15:19:06.025--ServerSession(2113649746)--Thread(Thread[Finalizer,8,system])--End undeploying Persistence Unit MyLibPU; session file:/home/Rox/MyLib/trunk/MyLib/src/_MyLibPU; state Deployed; factoryCount 2 
Apr 23, 2012 3:19:06 PM com.sun.xml.internal.ws.server.sei.EndpointMethodHandler invoke 
SEVERE: Exception [EclipseLink-28017] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.EntityManagerSetupException 
Exception Description: Unable to predeploy PersistenceUnit [MyLibPU] in invalid state [Undeployed] 
javax.persistence.PersistenceException: Exception [EclipseLink-28017] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.EntityManagerSetupException 
Exception Description: Unable to predeploy PersistenceUnit [MyLibPU] in invalid state [Undeployed] 
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:956) 
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:121) 
    at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source) 
    at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source) 
    at com.mylib.MyImplementation.getPersons(MyImplementation.java:171) 
    at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:601) 
    at com.sun.xml.internal.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:235) 
    at com.sun.xml.internal.ws.server.InvokerTube$2.invoke(InvokerTube.java:135) 
    at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:246) 
    at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:85) 
    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:626) 
    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:585) 
    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:570) 
    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:467) 
    at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:299) 
    at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:593) 
    at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244) 
    at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(WSHttpHandler.java:95) 
    at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(WSHttpHandler.java:80) 
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77) 
    at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83) 
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:80) 
    at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:668) 
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77) 
    at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:640) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) 
    at java.lang.Thread.run(Thread.java:722) 
Caused by: Exception [EclipseLink-28017] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.EntityManagerSetupException 
Exception Description: Unable to predeploy PersistenceUnit [MyLibPU] in invalid state [Undeployed] 
    at org.eclipse.persistence.exceptions.EntityManagerSetupException.cannotPredeploy(EntityManagerSetupException.java:202) 
    ... 30 more 

[EL Finer]: 2012-04-23 15:20:06.003--Thread(Thread[pool-1-thread-61,5,main])--fixUNC: before fixing: url = file:/home/Rox/MyLib/build/classes/, authority = , file = /home/Rox/MyLib/build/classes/ (There is no English translation for this message.) 
[EL Finer]: 2012-04-23 15:20:06.012--Thread(Thread[pool-1-thread-61,5,main])--fixUNC: after fixing: url = file:/home..... 

EDIT 2
我的persistence.xml:

<?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="MyLibPU" transaction-type="RESOURCE_LOCAL"> 
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 
    <class>com.mylib.Person</class> 
    <class>com.mylib.Group</class> 
    <properties> 
     <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/MY_DB"/> 
     <property name="javax.persistence.jdbc.password" value="MyPassword"/> 
     <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> 
     <property name="javax.persistence.jdbc.user" value="root"/> 
     <property name="eclipselink.logging.level" value="FINEST"/>; 
     <property name="eclipselink.logging.level.sql" value="FINEST"/>; 
     <property name="eclipselink.logging.parameters" value="true"/>; 
    </properties> 
    </persistence-unit> 
</persistence> 
+0

有更多的例外嗎? EclipseLink在創建持久性單元時出錯,所以如果沒有更多的錯誤,您需要將日誌記錄轉換爲最佳狀態以查找更多信息:。稍後獲得工廠可能「有效」,因爲該單元的大部分可能在錯誤發生之前已經初始化,但是沒有辦法告訴哪些不是。不應該丟棄創建工廠的例外情況。 – Chris 2012-04-20 14:06:45

+0

@克里斯:對不起,回覆晚了。在上面的文章中查看我的編輯,當EclipseLink日誌記錄設置爲FINEST時,您將輸出結果。你會在我上面的編輯中看到整個異常。你能弄清楚問題是什麼?我不能。 =/ – Rox 2012-04-24 07:08:17

+0

即使在編輯之後,應該有更多堆棧跟蹤。檢查服務器。任何方式發佈您的'persistence.xml'。那裏有什麼不對。甚至可能是無法解析的無效XML。 – Shahzeb 2012-04-24 07:13:12

回答

0

沒有與取消部署Hibernate的問題。當您嘗試取消部署和重新部署時,您似乎遇到了這些問題。當你重新啓動服務器時,你有問題嗎?

編輯:對不起,你清楚地說你使用EclipseLink,不知道爲什麼我認爲你使用Hibernate。

在任何情況下,這條線在您的記錄令人擔憂:

[EL Finest]: 2012-04-23 15:19:06.025--ServerSession(2113649746)--Thread(Thread[Finalizer,8,system])--Begin undeploying Persistence Unit MyLibPU; session file:/home/Rox/MyLib/trunk/MyLib/src/_MyLibPU; state Deployed; factoryCount 3 

我不知道什麼factoryCount手段,但我不喜歡,這是> 1。最令人擔憂的,雖然是「開始取消部署持久性單元MyLibPU「。爲什麼PU未被部署?我認爲這是因爲你沒有部署應用程序,但是在你的評論中你會說「錯誤可以在應用程序的整個生命週期的任何時候發生,並且每24小時只發生2-5次。」在這種情況下,你需要弄清楚什麼是觸發解除部署。

+0

我可以檢查並返回答案。但我沒有運行Hibernate。我正在運行EclipseLink。這些錯誤可以在應用程序的整個生命週期中隨時發生,並且每24小時只發生2-5次,並且不會遇到任何麻煩或其他問題。他們只是發生。 :-) – Rox 2012-04-25 08:46:53

1

如果錯誤是零星的,也許這意味着它是一個計時問題。此外,顯然你在應用程序的生命週期中多次創建工廠(讓我知道如果我錯了)。所以,它發出的併發請求到您的Web應用程序觸發工廠的併發創建。這種情況可能不被支持。

無論如何,創建工廠只需要一次。有關如何操作,請參見this question。然後你可以同時調用createEntityManager - 這種方法是線程安全的。

0

處理數據庫時不要使用靜態構造函數或類似構造。這可能會避免麻煩。嘗試在代碼中插入暫停和明確的日誌命令以查找錯誤,以查找代碼走多遠。

相關問題