You are currently browsing legacy 3.0 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Session: How to defer operations?

Operations can be deferred till saveChanges is called by using defer method in advanced() session operations. There are four types of commands that can be deferred:

Syntax

public void defer(ICommandData... commands);
Parameters
ICommandData[] Array of commands implementing ICommandData interface.  

Example

Product product1 = new Product();
product1.setName("My Product");
product1.setSupplier("suppliers/999");

PutCommandData command1 = new PutCommandData();
command1.setKey("products/999");
command1.setDocument(RavenJObject.fromObject(product1));
command1.setMetadata(new RavenJObject());

session.advanced().defer(command1);

Supplier supplier = new Supplier();
supplier.setName("My Supplier");

PutCommandData command2 = new PutCommandData();
command2.setKey("suppliers/999");
command2.setDocument(RavenJObject.fromObject(supplier));
command2.setMetadata(new RavenJObject());

session.advanced().defer(command2);

DeleteCommandData deleteCommandData = new DeleteCommandData();
deleteCommandData.setKey("products/1");
session.advanced().defer(deleteCommandData);