Use eclipselink.persistence-context.reference-mode
to specify if hard or soft (that is, weak) references are used within the Persistence Context.
Values
Table 5-80 describes this persistence property's values.
Table 5-80 Valid Values for persistence-context.reference-mode
Value | Description |
---|---|
|
(Default) EclipseLink references all objects through hard references. These objects will not be available for garbage collection until the referencing artifact (such as the persistence context or unit of work) is released/cleared or closed. |
|
References to objects supporting active attribute change tracking (see "@ChangeTracking") will be held by weak references. That is, any object no longer referenced directly or indirectly will be available for garbage collection. When a change is made to a change-tracked object, that object is moved to a hard reference and will not be available for garbage collection until flushed. Note: Any changes that have not been flushed in these entities will be lost. New and removed objects, as well as objects that do not support active attribute change tracking, will also be held by hard references and will not be available for garbage collection. |
|
All objects, including non-change-tracked objects, are to be held by weak references. When a change is made to a change-tracked object (see "@ChangeTracking"), that object is moved to a hard reference and will not be available for garbage collection until flushed. However, any objects that do not support active attribute change tracking may be garbage collected before their changes are flushed to a database, which can potentially result in a loss of changes. New and removed objects will be held by hard references and will not be available for garbage collection. |
Usage
The property set in persistence.xml
or passed to createEntityManagerFactory
affects all EntityManagers
created by the factory. To apply the property to specific EntityManagers
pass it to createEntityManager
method.
Examples
Example 5-79 shows how to use this property in a persistence.xml
file.
Example 5-79 Using persistence-context.reference-mode in persistence.xml
<property name="eclipselink.persistence-context.reference-mode" value="FORCE_WEAK"/>
Example 5-79 shows how to use this property in a property map.
Example 5-80 Using persistence-context.reference-mode in Property Map
import org.eclipse.persistence.config.PersistenceUnitProperties; propertiesMap.put(PersistenceUnitProperties.PERSISTENCE_CONTEXT_REFERENCE_MODE, ReferenceMode.FORCE_WEAK);
See Also
For more information, see: