Book Image

Learning NHibernate 4

Book Image

Learning NHibernate 4

Overview of this book

Table of Contents (18 chapters)
Learning NHibernate 4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Entity states


From the time you create a new instance of an entity in memory till the time the instance is saved in the database, the entity instance goes through different states from NHibernate's point of view. It is important to understand these states because NHibernates's persistence behavior is largely dependent on this state of the entity. Depending on the state of the entity, you are allowed or not allowed to perform some operations on it. This state information is completely isolated from the entity instances and the entity itself is not aware of its own state. NHibernate manages the state of entities separately. To understand entity states, let's first look into some scenarios around saving/deleting entities.

When we create a new instance of an entity in the application, NHibernate is not aware of this instance. This instance is also not saved in the database yet and as such only exists in the application memory. Any changes you make to this entity instance would not be saved in...