gpt4 book ai didi

java.lang.ClassCastException : org. apache.tomcat.dbcp.dbcp2.PoolingDataSource$PoolGuardConnectionWrapper 无法转换为 oracle.jdbc.OracleConnection

转载 作者:行者123 更新时间:2023-11-28 22:39:12 33 4
gpt4 key购买 nike

我正在尝试在 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>

Tomcat 9 是否支持将 Eclipsenik 作为 JPA 提供程序?如果没有,有什么办法可以解决这个问题吗?

最佳答案

问题是您使用的是 Oracle9Platform 目标数据库平台,它依赖于 native 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 实现。此代码然后使用基类在连接上调用 connection.getMetaData().getConnection();。如果这不起作用,您将必须实现自己的解包方法以从您的代理访问底层 OracleConnection。

然后您通过“eclipselink.target-server”持久性属性指定您希望使用的目标服务器平台类:

<property name="eclipselink.target-server" value="yourPackage.yourClass"/>

关于java.lang.ClassCastException : org. apache.tomcat.dbcp.dbcp2.PoolingDataSource$PoolGuardConnectionWrapper 无法转换为 oracle.jdbc.OracleConnection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57653516/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com