Remove the existing annotations and annotate the list with @Lob - indicates that the persistent property or field should be saved as a large object for the database - a supported large type of object .
If the variable type was a subtype of Serializable, you can simply leave annotations at all; JPA rules for default mappings indicate that types that are Serializable rather than primitive or Embeddable are serialized and stored in BLOB columns. However, List is not Serializable, although ArrayList.
You can use @Lob with @ElementCollection, but I'm not sure what the result is; I don't know if this serializes the entire list or creates a table in which each list item is serialized separately. You probably are not interested in this anyway.
MUCH LAST CHANGES: Of course, as the specifier studies hard, this annotation only works for fields of the Serializable type, and not for fields that simply contain objects of the Serializable class. Therefore, to do this work, you have to do fraud. I looked to see if it is possible to do something smart with a common wildcard limited by the type of intersection, but I don't think you can. You can, however, write a small class as follows:
class SerializableInstanceOf<T> implements Serializable { public final T instance; public SerializableInstanceOf(T instance) { Serializable s = (Serializable)instance; this.instance = instance; } }
And use this as a holder for the list - the object has a field of this type, marked with @Lob, and stores the link to the list in it. Each time you want to work with a list, you go through the instance field, possibly using the getList method for the object.
This is ugly, but it should allow you to do what you need.
source share