0

After reading one and once again oracle's documentation and not sure why I having this exception

Caused by: java.lang.ClassCastException: oracle.sql.BFILE cannot be cast to oracle.sql.BFILE

@Inject
@OracleProduction
private EntityManager em;

public String readBfileImage() {
    Session hibernateSession = em.unwrap(Session.class);
    SessionImplementor sessionImplementor = hibernateSession.unwrap(SessionImplementor.class);
    Connection connection = sessionImplementor.connection();

    Statement stmt = null;
    BFILE my_bfile = null;
    String result = "";
    try {
        stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT BFILE_COLUMN FROM TABLE_NAME where PARAM = 1");
        while (rs.next()) {
            BFILE objImagen = (BFILE) rs.getObject(1); // HERE THE EXCEPTION, WHY?

            System.out.println(objImagen.getName());
        }
        String ruta = my_bfile.getName();
        result = Base64.getEncoder().encodeToString(my_bfile.getBytes());
    } catch (SQLException e) {
        //throwing the exception
    }
    return result;
}

Also, I need to find a way to persist an image inside this file_column but hardly can not read using this way, would love to read answers!

In addition to this, I want to share the following image to note the type of the statement or resultSet is a WrapperResultSetJDK8, so what that is mean?

enter image description here

jthmiranda
  • 73
  • 1
  • 7
  • Debugging: cast it to an Object instead of BFILE, and check the class loaders on the classes involved. Your BFILE class that is the result is being caste to (tied to the current readBfileImage object) must be different than the one used to load the JDBC driver which is returning the results. – Chris Aug 23 '23 at 18:20

0 Answers0