I’m using JPA2 with hibernate 3.6.1. and a Derby database and I used the following annotation for a blob:
@Column(length = Integer.MAX_VALUE)
@Lob
long[] bucket;
Hibernate creates the correct blob column but if I try to save an entity I get the following exception:
java.lang.ClassCastException: [J cannot be cast to java.sql.Blob
why and how can I make this work?
If I annotate it without the @Lob I get a “Varchar for bit data” column which can only contain up to 32m.
You need to map the property as a byte[], not as long[].
The documentation says
If you want to persist the array, you’ll need to build a custom user type to transform the data type. You can find an example here http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/entity.html#d0e2794