Session: Storing Entities
To store entities inside the session object, use one of the three store
methods.
Syntax
First overload: Stores the entity in a session, then extracts the ID from the entity or generates a new one if it's not available.
void store(Object entity);
Second overload: Stores the entity in a session with given ID.
void store(Object entity, String id);
Third overload: Stores the entity in a session with given ID, forces concurrency check with given change vector.
void store(Object entity, String changeVector, String id);
Parameters | ||
---|---|---|
entity | Object | Entity that will be stored |
changeVector | String | Entity changeVector, used for concurrency checks (null to skip check) |
id | String | Entity will be stored under this ID, (null to generate automatically) |
Example
Employee employee = new Employee();
employee.setFirstName("John");
employee.setLastName("Doe");
// generate Id automatically
session.store(employee);
// send all pending operations to server, in this case only `Put` operation
session.saveChanges();