I want to store an double[]
array as Blob
in a database with Hibernate. But when I marked the property as Lob
, something like this:
@Entity
class MyEntity {
@Lob
double[] data;
}
I got the error D cannot be cast to java.sql.Blob
. (Wherein for the double[][]
array this is works...) So, my question is how to persis dobule[]
array with Hibernate?
UPD I forgot the main thing, sorry... The array is big enough, some thousand of values (more specific 5000-20000 values). And I want use the Blob
compression option from H2
database. So, I need the Lob
, but not List
.
UPD2 Another detail, it is read-only array.
In my opinion, using @ElementCollection
for that and letting Hibernate deal with optimizations is best:
@Entity
class MyEntity {
@ElementCollection
List<Double> data;
}
@Lob annotation doesn't support double[] type. Types supported by @Lob are:
What you could do is create a custom serializable class and use it instead
@Entity
class MyEntity {
@Lob
DoubleArray data;
}
public class DoubleArray implements Serializable {
private double[] data;
//constructor, getter and setter
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.