java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp2.PoolingDataSource$PoolGuardConnectionWrapper 无法转换为 oracle.jdbc.OracleConnection
java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp2.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to oracle.jdbc.OracleConnection
我正在尝试在 Tomcat 9 上部署我的应用程序,并且我的应用程序使用 eclipselink 作为 JPA 提供程序。我的应用程序 运行 在 WebLogic 12 服务器上运行良好,但在 Tomcat 9 上部署我的应用程序后,出现以下异常
javax.persistence.PersistenceException: java.lang.ClassCastException:
org.apache.tomcat.dbcp.dbcp2.PoolingDataSource$PoolGuardConnectionWrapper
cannot be cast to oracle.jdbc.OracleConnection at
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:480)
at
com.temp.request.dao.hybrid.PartyRequestSearchDAOImpl.retrieveRequestsByFilter(PartyRequestSearchDAOImpl.java:543)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:338)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at
org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89)
at
com.temp.request.util.aspect.TraceLogger.logMethodEntryAndExit(TraceLogger.java:36)
at sun.reflect.GeneratedMethodAccessor64.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:643)
at
org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:632)
at
org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at
org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89)
at
com.temp.request.util.aspect.ExecutionTimeLogger.logMethodExecutionTime(ExecutionTimeLogger.java:37)
at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:643)
at
org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:632)
at
org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy89.retrieveRequestsByFilter(Unknown Source)
Caused by: java.lang.ClassCastException:
org.apache.tomcat.dbcp.dbcp2.PoolingDataSource$PoolGuardConnectionWrapper
cannot be cast to oracle.jdbc.OracleConnection
我已经在我的 server.xml
中添加了 accessToUnderlyingConnectionAllowed="true"
我的server.xml如下
<GlobalNamingResources>
<Resource name="jdbc/DS_RW" auth="Container" type="javax.sql.DataSource"
username="user1" password="pass123" driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@temp.com:1545/service01"
accessToUnderlyingConnectionAllowed="true" />
</GlobalNamingResources>
Tomcat9 是否支持将 Eclipsenik 作为 JPA 提供程序?如果没有,有什么办法可以解决这个问题吗?
问题是您使用的是Oracle9Platform 目标数据库平台,它依赖于本机Oracle 连接,但您使用的连接池正在包装连接。 EclipseLink 使用 ServerPlatform 实现来允许特定于服务器的代码解开连接,但没有 Tomcat 的实现,因此它默认使用只是交回连接的 NoServerPlatform。
要使其正常工作并在 Tomcat 上使用 Oracle 特定的数据库功能,您需要创建一个类似于 https://github.com/ftahmed/eclipselink-server-platform-tomcat/blob/master/src/main/java/org/eclipse/persistence/platform/server/tomcat/TomcatPlatform.java 的 ServerPlatform 实现
此代码然后使用基础 class 在连接上调用 connection.getMetaData().getConnection();
。如果这不起作用,您将必须实现自己的解包方法以从您的代理访问底层 OracleConnection。
然后您通过 "eclipselink.target-server" 持久性 属性:
指定您希望使用的目标服务器平台 class
<property name="eclipselink.target-server" value="yourPackage.yourClass"/>
我正在尝试在 Tomcat 9 上部署我的应用程序,并且我的应用程序使用 eclipselink 作为 JPA 提供程序。我的应用程序 运行 在 WebLogic 12 服务器上运行良好,但在 Tomcat 9 上部署我的应用程序后,出现以下异常
javax.persistence.PersistenceException: java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp2.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to oracle.jdbc.OracleConnection at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:480) at com.temp.request.dao.hybrid.PartyRequestSearchDAOImpl.retrieveRequestsByFilter(PartyRequestSearchDAOImpl.java:543) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:338) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89) at com.temp.request.util.aspect.TraceLogger.logMethodEntryAndExit(TraceLogger.java:36) at sun.reflect.GeneratedMethodAccessor64.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:643) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:632) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89) at com.temp.request.util.aspect.ExecutionTimeLogger.logMethodExecutionTime(ExecutionTimeLogger.java:37) at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:643) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:632) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) at com.sun.proxy.$Proxy89.retrieveRequestsByFilter(Unknown Source) Caused by: java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp2.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to oracle.jdbc.OracleConnection
我已经在我的 server.xml
中添加了 accessToUnderlyingConnectionAllowed="true"我的server.xml如下
<GlobalNamingResources>
<Resource name="jdbc/DS_RW" auth="Container" type="javax.sql.DataSource"
username="user1" password="pass123" driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@temp.com:1545/service01"
accessToUnderlyingConnectionAllowed="true" />
</GlobalNamingResources>
Tomcat9 是否支持将 Eclipsenik 作为 JPA 提供程序?如果没有,有什么办法可以解决这个问题吗?
问题是您使用的是Oracle9Platform 目标数据库平台,它依赖于本机Oracle 连接,但您使用的连接池正在包装连接。 EclipseLink 使用 ServerPlatform 实现来允许特定于服务器的代码解开连接,但没有 Tomcat 的实现,因此它默认使用只是交回连接的 NoServerPlatform。
要使其正常工作并在 Tomcat 上使用 Oracle 特定的数据库功能,您需要创建一个类似于 https://github.com/ftahmed/eclipselink-server-platform-tomcat/blob/master/src/main/java/org/eclipse/persistence/platform/server/tomcat/TomcatPlatform.java 的 ServerPlatform 实现
此代码然后使用基础 class 在连接上调用 connection.getMetaData().getConnection();
。如果这不起作用,您将必须实现自己的解包方法以从您的代理访问底层 OracleConnection。
然后您通过 "eclipselink.target-server" 持久性 属性:
指定您希望使用的目标服务器平台 class<property name="eclipselink.target-server" value="yourPackage.yourClass"/>