This is not a direct answer to OP’s question, as I did not have to deal with an Instance of ‘WrappedClob’. But as I still got the same misleading error message, I hope someone finds this useful:
The problem for me was, that hibernates implementation of ‘Clob to String’ for H2 and Postgres did not behave the same way. So, while my tests worked fine, the application would crash at runtime. To work around this, I instantiated different beans of ClobReader in different environments.
The production environment would us the bean implementation for Postgres, while the test code uses the H2 bean.
public interface ClobReader {
String clobToString(Object clob) throws SQLException, IOException;
}
@Bean
public ClobReader clobReaderPostgres() {
return new ClobReader() {
@Override
public String clobToString(final Object clob) {
if (clob == null) {
return null;
}
return clob.toString();
}
};
}
@Bean
@Primary
public ClobReader clobReaderH2() {
return new ClobReader() {
@Override
public String clobToString(final Object obj) throws SQLException, IOException {
final Clob clob = (Clob) obj;
try (final Reader reader = clob.getCharacterStream()) {
try (final StringWriter stringWriter = new StringWriter()) {
IOUtils.copy(reader, stringWriter);
return stringWriter.toString();
}
}
}
};
}