Hello,
is it possible to insert or update @Lob annotated fields with an hql query? I'm using Hibernate 4 + JPA 2, but issue occured also on earlier versions.
When I try the following:
Code:
public void mergeChunks(String fileName, File data) {
Query query = getEntityManager()
.createQuery(
"UPDATE TempFile SET dataHolder.data = dataHolder.data + :data WHERE fileName = :fileName");
query.setParameter("fileName", fileName);
try {
query.setParameter("data",
IOUtils.toByteArray(new FileInputStream(data)));
} catch (IOException e) {
LogFactory.getLog(TempFileService.class).error(e);
}
query.executeUpdate();
}
I get this error:
Code:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set data=data+_binary'%PDF-1.6 %???? 3 0 obj<
I'm looking for something similiar to java.sql.PreparedStatement.setBinaryStream method. How to accomplish it with JPA??? I would be grateful for your help.
Cheers,
Wojciech