JPA1 provides a way for users to specify that a field will be persisted
. This is of use,
for example, to collections/maps/arrays which typically are stored using join tables or foreign-keys to other
records. By specifying that a field is serialised a column will be added to store that field and the field will
be serialised into it.
JPA1's definition of serialising applies to any field and all in the same way, unlike the situation with
JDO2 which provides much more flexibility. Perhaps the most important thing to bear in mind when deciding
to serialise a field is that that object in the field being serialised must implement
If you wish to serialise a particular field into a single column (in the table of the class), you need
to simply mark the field as a "lob" (large object). Let's take an example. We have the following classes
and we want the
collection to be serialised into a single column in the table
class, so we define our MetaData like this
So we make use of the
element (or @Lob annotation). This specification results in a table
Provisos to bear in mind are
Queries cannot be performed on collections stored as serialised.
If the field that we want to serialise is of type String, byte, char, Byte or Character
then the field will be serialised into a CLOB column rather than BLOB.
See also :-