Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unwrap instead of cast to get implementation specific interface in EclipseLink Oracle Extension #2058

Open
peterzberg opened this issue Feb 7, 2024 · 1 comment

Comments

@peterzberg
Copy link

Describe the bug
In a container environment, connections, statements, .. may be wrapped. So casting to the expected class will fail.

Example: https://github.com/eclipse-ee4j/eclipselink/blob/4.0.2/foundation/org.eclipse.persistence.oracle/src/main/java/org/eclipse/persistence/platform/database/oracle/Oracle9Platform.java#L178

In Openliberty, this PreparedStatement is a com.ibm.ws.rsadapter.jdbc.v43.WSJdbc43PreparedStatement that wrapps the OraclePreparedStatement which leads to "java.lang.ClassCastException: class com.ibm.ws.rsadapter.jdbc.v43.WSJdbc43PreparedStatement cannot be cast to class oracle.jdbc.OraclePreparedStatement "

To Reproduce
Steps/resources to reproduce the behavior:

  • EclipseLink version: 4.0.2
  • Java/JDK version: x
  • Entity source (mainly applied annotations)
@TypeConverters({
  @TypeConverter(name = "nvarcharConvProperty", dataType=org.eclipse.persistence.platform.database.oracle.NString.class, objectType=String.class)
})
  1. For problem in persistence (JPA)
    • JPA context like persistence.xml settings or related system properties (in case of JPA): Nothing special
    • Database provider/version: com.oracle.database.jdbc:ojdbc11:23.2.0.0
    • JDBC driver provider/version (it should be useful if bug is related with some "specific" datatype e.g. JSON): com.oracle.database.jdbc:ojdbc11:23.2.0.0

Expected behavior
Statements gets unwrapped and no ClassCastException will be thrown.

Additional context
The problem occured within Openliberty 23.0.0.12. I can try to create an example to reproduce this behaviour. I can try to create an example if needed.

@peterzberg
Copy link
Author

OraclePreparedStatement oraclePreparedStatement = statement.unwrap(OraclePreparedStatement.class);
oraclePreparedStatement.setFormOfUse(index, oracle.jdbc.OraclePreparedStatement.FORM_NCHAR);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant