Top Description Methods
org.eclipse.persistence.annotations

public @Interface SerializedObject

extends Annotation
Annotations
@Target:TYPE
@Retention:RUNTIME
Imports
org.eclipse.persistence.config.QueryHints, java.lang.annotation.Retention, .Target, jakarta.persistence.Column

SerializedObject annotation is used to set an org.eclipse.persistence.descriptors.SerializedObjectPolicy on an Entity or MappedSuperClass. 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.

Examples:


@Entity
@SerializedObject(MySerializedObjectPolicy.class);
public class Employee {...

@Entity
@SerializedObject(value = MySerializedObjectPolicy.class, column = @Column(name="SERIALIZED"));
public class Address {...
If SerializedObjectPolicy is set on an entity then SerializedObjectPolicies with the same field are set on all inheriting entities. 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

Examples:


Query query = em.createQuery("SELECT e FROM Employee e").setHint(QueryHints.SERIALIZED_OBJECT, "true");

Map hints = new HashMap();
hints.put("eclipselink.serialized-object", "true");
Address address = em.find(Address.class, id, hints);
The goal is to make reads from the database faster. The draw back 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.
Author
ailitche
Since
EclipseLink 2.5.1
See Also
org.eclipse.persistence.descriptors.SerializedObjectPolicy

Method Summary

Modifier and TypeMethod and Description
public Column
column()

(Optional) The column that holds the serialized object.

public Class<?>
value()

The Class that implements org.eclipse.persistence.descriptors.SerializedObjectPolicy interface.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

columnback to summary
public Column column()

(Optional) The column that holds the serialized object. By default it's a BLOB column named "SOP" in entity's main table.

valueback to summary
public Class<?> value()

The Class that implements org.eclipse.persistence.descriptors.SerializedObjectPolicy interface. This class must be specified.