C# Python Node.JS
Article For
1.0 2.0 2.5 3.0 3.5 4.1 4.2 5.0

Session: Deleting Entities

Entities can be marked for deletion by using the delete method, but will not be removed from the server until saveChanges is called.


<T> void delete(T entity);

void delete(String id);

void delete(String id, String expectedChangeVector);
entity or id T or String instance of the entity to delete or entity ID
expectedChangeVector String a change vector to use for concurrency checks

Example I

Employee employee = session.load(Employee.class, "employees/1");


Concurrency on Delete

If useOptimisticConcurrency is set to 'true' (default 'false'), the delete() method will use loaded 'employees/1' change vector for concurrency check and might throw ConcurrencyException.

Example II


Concurrency on Delete

In this overload, the delete() method will not do any change vector based concurrency checks because the change vector for 'employees/1' is unknown.


If entity is not tracked by session, then executing


is equal to doing

session.advanced().defer(new DeleteCommandData("employees/1", null));

Change Vector in DeleteCommandData

In this sample the change vector is null - this means that there will be no concurrency checks. A non-null and valid change vector value will trigger a concurrency check.

You can read more about defer operations here.