jthmiranda
jthmiranda

Reputation: 73

oracle.sql.BFILE cannot be cast to oracle.sql.BFILE

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

Upvotes: 0

Views: 158

Answers (1)

Kuassi Mensah
Kuassi Mensah

Reputation: 312

Can you try replacing oracle.jdbc.OracleBlob with java.sql.Blob?

Upvotes: 0

Related Questions