7.1.1.7 Item

There are also the more fine-grained save and refresh methods on Item.

javax.jcr.
Item

void

save()

Validates all pending changes currently recorded in this Session that apply to this Item or any of its descendants (that is, the subtree rooted at this Item). If validation of all pending changes succeeds, then this change information is cleared from the Session. If the save occurs outside a transaction, the changes are persisted and thus made visible to other Sessions. If the save occurs within a transaction, the changes are not persisted until the transaction is committed (see 8.1 Transactions for more details).

If validation fails, then no pending changes are saved and they remain recorded on the Session. There is no best-effort or partial save.

The item in persistent storage to which a transient item is saved is determined by matching UUIDs and paths. See 7.1.2 Saving by UUID and Path, for details.

An AccessDeniedException will be thrown if any of the changes to be persisted would violate the access permissions of the Session.

If any of the changes to be persisted would cause the removal of a node that is currently the target of a REFERENCE property then a ReferentialIntegrityException is thrown, provided that this Session has read access to that REFERENCE property. If, on the other hand, this Session does not have read access to the REFERENCE property in question, then an AccessDeniedException is thrown instead.

An ItemExistsException will be thrown if any of the changes to be persisted would be prevented by the presence of an already existing item in the workspace.

A ConstraintViolationException will be thrown if any of the changes to be persisted would violate a node type restriction. Additionally, a repository may use this exception to enforce implementation- or configuration-dependant restrictions.

An InvalidItemStateException is thrown if any of the changes to be persisted conflicts with a change already persisted through another session and the implementation is such that this conflict can only be detected at save-time and therefore was not detected earlier, at change-time.

A ReferentialIntegrityException is thrown if any of the changes to be persisted would cause the removal of a node that is currently referenced by a REFERENCE property that this Session has read access to.

A VersionException is thrown if the save would result in a change to persistent storage that would violate the read-only status of a checked-in node.

A LockException is thrown if the save would result in a change to persistent storage that would violate a lock.

A NoSuchNodeTypeException is thrown if the save would result in the addition of a node with an unrecognized node type.

A RepositoryException will be thrown if another error occurs.

void

refresh(boolean keepChanges)

If keepChanges is false, this method discards all pending changes currently recorded in this Session that apply to this Item or any of its descendants (that is, the subtree rooted at this Item) and returns these items to reflect the current saved state. Outside a transaction this state is simply the current state of persistent storage. Within a transaction, this state will reflect persistent storage as modified by changes that have been saved but not yet committed.

If keepChanges is true then pending changes are not discarded but items (within the subtree rooted at this Item) that do not have changes pending have their state refreshed to reflect the current saved state, thus revealing changes made by other sessions. In some implementations this may be a null operation. See 7.1.3.4 Seeing Changes Made by Other Sessions, for more details.

An InvalidItemStateException is thrown if this Item object represents a workspace item that has been removed (either by this session or another).

A RepositoryException is thrown if another error occurs.