在Weblogic 10下,我使用Hibernate将数据存储到几个带有BLOB的表中。它总是工作得很好,但客户发现在特定情况下,15%的BLOB大小正确,但只包含空字符。我不知道是什么让它变得好或充满空虚。
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
if (value == null) {
st.setNull(index, sqlTypes()[0]);
return;
}
try {
Connection conn = st.getConnection();
if (conn instanceof org.apache.commons.dbcp.DelegatingConnection) {
log.debug("Delegating connection, digging for actual driver");
conn = ((org.apache.commons.dbcp.DelegatingConnection)st.getConnection()).getInnermostDelegate();
}
OutputStream tempBlobWriter = null;
BLOB tempBlob = BLOB.createTemporary(conn, true, BLOB.DURATION_SESSION);
try {
tempBlob.open(BLOB.MODE_READWRITE);
tempBlobWriter = tempBlob.setBinaryStream(1L);
tempBlobWriter.write((byte[])value);
tempBlobWriter.flush();
} finally {
if (tempBlobWriter != null)
tempBlobWriter.close();
tempBlob.close();
}
st.setBlob(index, (Blob) tempBlob);
} catch (IOException e) {
throw new HibernateException(e);
}
}
我在那里放了一个日志,可以确认值(byte[])是正确的。我试图更改createTemporary参数,但没有成功。
我在Weblogic 10.0(无法升级)下运行此程序,并附带Oracle Thin驱动程序。
一个线索是,工作调用来自WLS部署和管理的标准web服务。但是,有问题的调用是从一个线程开始的,该线程与使用JNI与某些遗留系统接口的组件一起启动的。除了这些BLOB,这条线对所有东西都很有魅力。在插入数据之前,我收到了一个新的会话,稍后将其关闭。(会话在线程的生命周期内不会保持打开状态)