Java 11 migration - createConnectionBuilder() from PoolDataSourceImpl clashes with createConnectionBuilder() from javax.sql.DataSource

故事扮演 提交于 2020-05-28 06:09:08

问题


I am trying to migrate a project from Java 8 to Java 11, which uses ojdbc. I am using a class which extends PoolDataSourceImpl, which implements PooLDataSource, which extends javax.sql.DataSource and while trying to built it with maven it gives this error:

Compilation failure [ERROR] createConnectionBuilder() in oracle.ucp.jdbc.PoolDataSourceImpl cannot implement create ConnectionBuilder() in javax.sql.DataSource [ERROR] return type oracle.ucp.jdbc.UCPConnectionBuilder is not compatible with java.sql.ConnectionBuilder

Does anyone have any suggestions?


回答1:


This is interface incompatibility. javax.sql.DataSource defines a method

default ConnectionBuilder createConnectionBuilder() throws SQLException

And as per the contract the return value requires to be of type ConnectionBuilder.

If you take a look at documentation of oracle.ucp.jdbc.PoolDataSourceImpl, it defines the method as

public UCPConnectionBuilder createConnectionBuilder()

whereas oracle.ucp.jdbc.UCPConnectionBuilder is not a subtype of java.sql.ConnectionBuilder.

Now unless Oracle releases a never version of oracle.ucp.jdbc.UCPConnectionBuilder interface that extends java.sql.ConnectionBuilder, you will not be able to interchange UCP PoolDataSource with javax.sql.DataSource.

The latest release at this point appears to be UCP 19.3, which would still hit the same problem which is unfortunate since 19.3 is advertised as JDK11 compliant. Please raise a bug against Oracle UCP to make the maintainers aware of the new entrant createConnectionBuilder in the DataSource interface.

In the intrim, if it is feasible, you may fall back to using 11g release 2 of UCP (not 12, not 19) which does not have the method createConnectionBuilder on the PoolDataSource interface. Not an ideal situation, since you are giving up on a decade worth of improvements in UCP by going back to 11g.




回答2:


The problem is that you try to subclass PoolDataSourceImpl which is a vendor-specific class compiled with JDK8 and we do not support extending our classes unless we explicitly suggest to do so, as in this blog; and this is true for all software vendors. A part from this restriction, our drivers (ojdbc8.jar, ucp.jar) are forward compatible with newer JDK releases (i.e., work with JDK11) and database releases.




回答3:


With this issue proxying with interface-based proxy on PoolDataSource will never work. A bug is logged on oracle ucp for the same. I even posted a forum query with no reply on this https://community.oracle.com/thread/4325841.



来源:https://stackoverflow.com/questions/60098095/java-11-migration-createconnectionbuilder-from-pooldatasourceimpl-clashes-wi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!