concept Save in category .net

appears as: Save
NHibernate in Action

This is an excerpt from Manning's book NHibernate in Action.

Notice how NHibernate detects the modification to the name and manager properties of the first Employee (Tobin) and automatically updates the database. You’re taking advantage of an NHibernate feature called automatic dirty checking: this feature saves you the effort of explicitly asking NHibernate to update the database when we modify the state of an object. Similarly, you can see that the new Employee (Pierre Henri) was saved when it was associated with the first Employee. This feature is called cascading save: it saves you the effort of explicitly making the new object persistent by calling Save(), as long as it’s reachable by an already persistent object (Tobin). Also, notice that the ordering of the SQL statements isn’t the same as the order in which you set fields of the object. NHibernate uses a sophisticated algorithm to determine an efficient ordering that avoids database foreign-key-constraint violations but is still sufficiently predictable to the user. This feature is called transactional write-behind.

public void Save( User user ) {
try {
session.SaveOrUpdate( user );
}
catch( HibernateException ex ) {
log.Error( "Error while saving a user.", ex );
throw new PersistenceException( "Error while saving a user.", ex );
}
}

Using an HQL query , you check whether the database contains a higher bid for the current item. If a higher bid exists, you display an error message. Otherwise, if all checks are successful, you place the new bid by adding it to the item . Note that you don’t have to save it manually by calling Save(); it’s saved using NHibernate’s transitive persistence (cascading from the Item to Bid).