Language
C#
Article For
3.5 4.0 4.1 4.2 5.0 5.1 5.2

Session: How to clear a session?

To clear session state, that is to stop tracking entities and remove all pending commands, etc. clear method is used from advanced() session operations.

Syntax

public void clear();

Example

Employee employee = new Employee();
employee.setFirstName("John");
employee.setLastName("Doe");

session.store(employee);

session.advanced().clear();

session.saveChanges(); // nothing will happen