Use @ExistenceChecking
to specify how TopLink should check to determine if an entity is new or exists.
On merge()
operations, use @ExistenceChecking
to specify if TopLink uses only the cache to determine if an object exists, or if the object should be read (from the database or cache). By default the object will be read from the database.
Table 2-20 describes this annotation's elements.
Table 2-20 @ExistenceChecking Annotation Elements
Annotation Element | Description | Default |
---|---|---|
|
(Optional) Set the existence checking type:
|
|
You can specify @ExistenceChecking
on an Entity or MappedSuperclass.
EclipseLink supports the following existence checking types:
ASSUME_EXISTENCE
– If the object's primary key does not include null
then it must exist. You may use this option if the application guarantees or does not care about the existence check.
ASSUME_NON_EXISTENCE
– Assume that the object does not exist. You may use this option if the application guarantees or does not care about the existence check. This will always force an INSERT
operation.
CHECK_CHACHE
– If the object's primary key does not include null
and it is in the cache, then it must exist.
CHECK_DATABASE
– Perform a SELECT
on the database.
Example 2-41 shows how to use this annotation.
Example 2-41 Using @ExistenceChecking Annotation
@Entity
@Cache(type=CacheType.HARD_WEAK, expiryTimeOfDay=@TimeOfDay(hour=1))
@ExistenceChecking(ExistenceType.CHECK_DATABASE)
public class Employee implements Serializable {
...
}
For more information, see:
"Enhancing Performance" in Solutions Guide for Oracle TopLink