Session: Storing entities in session

To store entities inside session object use one of the four store methods.

Syntax

First overload stores entity in session, extracts Id from entity using Conventions or generates new one if it is not available.

public void store(Object entity);

Second overload stores entity in session, extracts Id from entity using Conventions or generates new one if it is not available and forces concurrency check with given Etag.

public void store(Object entity, Etag etag);

Third overload stores entity in session with given id.

public void store(Object entity, String id);

Fourth overload stores entity in session with given id and forces concurrency check with given Etag.

public void store(Object entity, Etag etag, String id);
Parameters
entity Object Entity that will be stored
etag Etag Current entity etag, used for concurrency checks (null to skip check)
id String Entity will be stored under this key, (null to generate automatically)

Example

// generate Id automatically
// when database is new and empty database and conventions are not changed: 'employee/1'
Employee employee = new Employee();
employee.setFirstName("John");
employee.setLastName("Doe");
session.store(employee);

// send all pending operations to server, in this case only `put` operation
session.saveChanges();