【发布时间】:2020-02-21 05:22:48
【问题描述】:
我有下面的 jdbc sn-p,我想在休眠中使用本机查询进行转换。
问题:这是我的 jdbc 代码:
{
statement = conn.prepareStatement("INSERT INTO CCM_JIGSAW_FILES (FILE_ID,FILE_FOR,FILE_CONTENT)
VALUES (?,?,?)");
ByteArrayInputStream in = new ByteArrayInputStream(fileContent);//fileContent is byte[]
statement.setString(1, file_id);
statement.setString(2, licenseType);
statement.setBinaryStream(3,in,fileContent.length);
statement.executeUpdate();
}
已尝试的解决方案:尝试使用休眠模式,但运气不佳
{
String insertSqlQuery = "INSERT INTO CCM_JIGSAW_FILES (FILE_ID,FILE_FOR,FILE_CONTENT) VALUES (?,?,?)";
inputStream = new ByteArrayInputStream(fileContent);
Query insertQuery = entityManager.createNativeQuery(insertSqlQuery);
insertQuery.setParameter(1, fileId);
insertQuery.setParameter(2, licenseType);
insertQuery.setParameter(3, inputStream);// Here i am getting runtime exception.
insertQuery.executeUpdate();
}
org.hibernate.HibernateException: Could not determine a type for
class: java.io.ByteArrayInputStream
如何将statement.setBinaryStream(3,in,fileContent.length) 转换为休眠模式?
注:数据库中FILE_CONTENT的数据类型为Blob
【问题讨论】: