Annotation Interface SerializedObject
If SerializedObjectPolicy is specified Eclipselink writes out the whole entity object with its privately owned (and nested privately owned) entities and element collections into an additional (likely BLOB) field in the database. That field could be specified in the annotation, it defaults to "SOP" in the main table.
Example:
@Entity
@SerializedObject(MySerializedObjectPolicy.class);
public class Employee {
...
}
@Entity
@SerializedObject(value = MySerializedObjectPolicy.class, column = @Column(name="SERIALIZED"));
public class Address {
...
}
The query that uses SerializedObjectPolicy extracts the whole object from that field. To read object(s) using SerializedObjectPolicy the query should specify QueryHints.SERIALIZED_OBJECT
Example:
Query q = em.createQuery("SELECT e FROM Employee e").setHint(org.eclipse.persistence.config.QueryHints.SERIALIZED_OBJECT, "true");
Map<String, Object> hints = new HashMap<>();
hints.put("eclipselink.serialized-object", "true");
Address a = em.find(Address.class, id, hints);
The goal is to make reads from the database faster. The drawback is slower writes into the database. So SerializedObjectPolicy may make sense for read-only / read-mostly application for Entity, which always loads all its dependent entities and / or ElementCollections.
In case the serialized object column contains null or obsolete version of the object, the query using SerializedObjectPolicy would either throw exception or - if all other fields have been read, too - would build the object using these fields (exactly as in case SerializedObjectPolicy is not used).
Note that currently no default implementation of SerializedObjectPolicy is available and this class should be provided by the user.
- See Also:
- Author:
- ailitche
-
Required Element Summary
Required ElementsModifier and TypeRequired ElementDescriptionClass<?> The Class that implements SerializedObjectPolicy interface. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionjakarta.persistence.ColumnThe column that holds the serialized object.
-
Element Details
-
value
Class<?> valueThe Class that implements SerializedObjectPolicy interface. This class must be specified. -
column
jakarta.persistence.Column columnThe column that holds the serialized object.By default, it's a BLOB column named "SOP" in entity's main table.
- Default:
@jakarta.persistence.Column(name="SOP")
-