Open
Description
Andreas Klöber opened DATAJPA-1425 and commented
We encountered an error with HSQLDB when updating an entity with a Blob field while leaving that Blob untouched (only other fields are updated).
The error can be reproduced by running test case test.EventRepositoryTests#testBlobViaSpringData
in the following repo: https://github.com/akloeber/spring-data-bug-blob:
@Test
public void testBlobViaSpringData() throws SQLException {
Event event = new Event(
"foo",
BlobProxy.generateProxy(encodeString("bar"))
);
Long id = events.save(event).getId();
entityManager.flush();
entityManager.clear();
event = events.getOne(id);
event.setText("bazz");
events.save(event); // NOTE: not really necessary in this simple example but mandatory in order to provoke the error
entityManager.flush(); // -> yields error below
entityManager.clear();
event = events.getOne(id);
assertThat(decodeString(toBytes(event.getData()))).isEqualTo("bar");
assertThat(event.getText()).isEqualTo("bazz");
}
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not update: [test.Event#3]
...
Caused by: java.sql.SQLException: Invalid argument in JDBC call: invalid Reader
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.setBlobParameter(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.setBinStream(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.setBinaryStream(Unknown Source)
at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$5$1.doBind(BlobTypeDescriptor.java:156)
at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$2$1.doBind(BlobTypeDescriptor.java:86)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:74)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:280)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:275)
at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:39)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2729)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3168)
... 46 more
Caused by: org.hsqldb.HsqlException: Invalid argument in JDBC call: invalid Reader
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
... 58 more
There is also another test case test.EventRepositoryTests#testBlobViaJpa
which uses the JPA-API directly and does not provoke this error.
I was not able to reproduce the error against H2. The error does not occur if the data of the Blob is consumed and replaced by a new Blob like this:
event.setData(
BlobProxy.generateProxy(
event.getData().getBytes(1, Long.valueOf(event.getData().length()).intValue())
)
);
Affects: 2.0.10 (Kay SR10)