Identify correct and incorrect statements or examples about EntityManager operations for managing an instance's state, including eager/lazy fetching, handling detached entities, and merging detached entities.

[Note]

Detached Entities

A detached entity may result:

Detached entity instances continue to live outside of the persistence context in which they were persisted or retrieved, and their state is NO longer guaranteed to be synchronized with the database state.

The application may access the available state of available detached entity instances after the persistence context ends. The available state includes:

If the persistent field or property is an association, the available state of an associated instance MAY ONLY be safely accessed if the associated instance is available. The available instances include:

Merging Detached Entity State

The merge operation allows for the propagation of state from detached entities onto persistent entities managed by the EntityManager.

The semantics of the merge operation applied to an entity X are as follows:

The persistence provider MUST NOT merge fields marked LAZY that have not been fetched: it MUST IGNORE such fields when merging.

Any Version columns used by the entity MUST BE CHECKED by the persistence runtime implementation during the merge operation and/or at flush or commit time. In the absence of Version columns there is no additional version checking done by the persistence provider runtime during the merge operation.

Detached Entities and Lazy Loading

Serializing entities and merging those entities back into a persistence context may not be interoperable across vendors when lazy properties or fields and/or relationships are used.

A vendor is required to support the serialization and subsequent deserialization and merging of detached entity instances (which may contain lazy properties or fields and/or relationships that have not been fetched) back into a separate JVM instance of that vendor's runtime, where both runtime instances have access to the entity classes and any required vendor persistence implementation classes.

When interoperability across vendors is required, the application must not use lazy loading.

Managed Instances

It is the responsibility of the application to insure that an instance is managed in only a single persistence context. The behavior is undefined if the same Java instance is made managed in more than one persistence context.

The contains() method can be used to determine whether an entity instance is managed in the current persistence context.

The contains method returns true:

The contains method returns false:

Note that the effect of the cascading of persist or remove is IMMEDIATELY visible to the contains method, whereas the ACTUAL insertion or deletion of the database representation for the entity may be DEFERRED until the end of the transaction.

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free Mock Exam Engine