java.lang.ClassCastException: com.ibm.ws.jpa.management.JPATxEntityManager
I have a restful webservice using eclipselink2.0 as JPA provider deployed on WAS vs 7.0.00.19 with OSGI and JPA2.0 feature pack. I have created a shared library for the application pointing to the location of these jar files:
- c:\bacpext\eclipselink-javax.persistence-2.0.jar
- c:\bacpext\eclipselink-2.0.2.jar
An attempt to access a resource uri throws the following exception
[10/11/11 15:53:18:151 CEST] FFDC Exception:java.lang.ClassCastException Sou开发者_如何学运维rceId:com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch ProbeId:448 Reporter:com.ibm.ws.webcontainer.servlet.ServletWrapperImpl@2f412f41
java.lang.ClassCastException: com.ibm.ws.jpa.management.JPATxEntityManager incompatible with javax.persistence.EntityManager
at com.tavia.service.PersistenceService.<init>(PersistenceService.java:39)
at com.tavia.service.PersistenceService.<init>(PersistenceService.java:19)
at com.tavia.service.PersistenceService$1.initialValue(PersistenceService.java:29)
at com.tavia.service.PersistenceService$1.initialValue(PersistenceService.java:26)
at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:152)
at java.lang.ThreadLocal.get(ThreadLocal.java:142)
at com.tavia.service.PersistenceService.getInstance(PersistenceService.java:52)
at com.tavia.service.GltmMisCodesResource.get(GltmMisCodesResource.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:149)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:259)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:83)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:71)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:990)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:941)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:932)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:384)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:451)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:632)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1657)
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:179)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3935)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:931)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
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:1604)
Any ideas on what might be wrong?
It appears that PersistenceService has acquired a reference to an EM proxy that was created by the WAS runtime (JPATxEntityManager), but it is attempting to cast it to javax.persistence.EntityManager that has been overridden by eclipselink-javax.persistence-2.0.jar. Without knowing what you're trying to do, one of these is the problems:
- You should not include eclipselink-javax.persistence-2.0.jar to override javax.persistence; you should use the persistence API classes already provided by WebSphere.
- ...or you do want to override the persistence API classes for some reason. In this case, you should change the way the EM is acquired to ensure that it does not use injection or java:comp lookup, which will always return the JPATxEntityManager that is incompatible with the overridden javax.persistence APIs.
精彩评论