Session: How to refresh entity?
To update entity with latest changes from server refresh
method from advanced()
session operations can be used.
Syntax
public <T> void refresh(T entity);
Parameters | ||
---|---|---|
entity | T | Instance of an entity that will be refreshed |
Example
Employee employee = session.load(Employee.class, "employees/1");
assertEquals("Doe", employee.getLastName());
// LastName changed to 'Shmoe'
session.advanced().refresh(employee);
assertEquals("Shmoe", employee.getLastName());
Remarks
Refreshing transient entity (not attached) or entity that was deleted on server-side will result in InvalidOperationException
.