I am new to JPA and hibernate.
I am using HSQLDB 2.0 and hibernate-JPA to insert image into BINARY column. I have annotated as follows
@Lob
private byte[] profileImage;
I can insert the image into the database.
I am retrieving the entity from database along with the binary column and converting the byte array into Image.
But when I request to persist the entity again after an update, I am getting following error.
Caused by: org.hibernate.exception.DataException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:77)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
at org.hibernate.event.def.AbstractFlushingEventListener.开发者_如何学运维performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
... 68 more
Caused by: java.sql.BatchUpdateException: data exception: string data, right truncation at org.hsqldb.jdbc.JDBCPreparedStatement.executeBatch(Unknown Source) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246) ... 76 more
Can anyone please let me know what might be the issue?
Thank you in advance,
Regards, Niranjan
You need to use the latest Hibernate 3.6.2 and HSQLDB 2.1. Also, use a column of LONGVARBINARY or BLOB to store images. A BINARY column stores extra zero bytes after the image data to fill up its declared length, while the other two types do not add zero padding.
精彩评论