java – 我得到一个PersistenceException,我无法理解为什么
发布时间:2020-12-15 02:33:31 所属栏目:Java 来源:网络整理
导读:我正在使用 EclipseLink运行Web服务,它运行良好.但有时我得到一个例外,说“无法预先部署PersistenceUnit”.我不知道为什么我得到这个.其他所有东西似乎都有效,这个异常似乎并没有打扰到应用程序,它只是被捕获了. Exception Description: Unable to predeploy
我正在使用
EclipseLink运行Web服务,它运行良好.但有时我得到一个例外,说“无法预先部署PersistenceUnit”.我不知道为什么我得到这个.其他所有东西似乎都有效,这个异常似乎并没有打扰到应用程序,它只是被捕获了.
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"); 我为什么要这个? 编辑 [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,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,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,main])--fixUNC: after fixing: url = file:/home..... 编辑2 <?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> 解决方法
如果错误是零星的,也许这意味着它是一个时间问题.此外,显然您在应用程序的生命周期中多次创建工厂(如果我错了,请告诉我).因此,对您的Web应用程序的并发请求会触发并发创建工厂.可能不支持此案例.
无论如何,只创建一次工厂是好的.有关如何操作,请参阅this question.然后你可以同时调用createEntityManager – 这个方法是线程安全的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |