O'Reilly logo

Learning NHibernate 4 by Suhas Chatekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Transitive persistence using cascade styles

NHibernate implements transitive persistence wherein updates made to a persistent entity are automatically synchronized to database on commit of the transaction. Let's look at a very simple example of how this works. In the following unit test, we save a transient employee instance, thus making it persistent. We then load the persistent instance from database inside a new transaction, update the FirstName and LastName property, and commit the transaction. Lastly, we clear the session and load the same entity instance from database and confirm that FirstName and LastName is updated correctly.

[Test] public void UpdateEmployee() { object id = 0; using (var tx = Session.BeginTransaction()) { id = Session.Save(new ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required