Switching NHibernate to Business Transaction and Identity Keys

I would like to implement a dialog for each business transaction in a WPF application, as described here . Unfortunately, this application has a large existing database using SQL Server key-generated identifiers in all tables.

I know that adding a new object to an NHibernate session will insert it if it has an identification key. Fabio has a template that completes the current transaction at the end of each request, although we have not yet completed the entire block of work.

If I understand correctly, this means that my objects will be inserted into the database and not deleted, even if I refuse the unit of work. So:

  • Is this pattern incompatible with identity keys?
  • Is there any reasonable work around?
  • Is there a better sample that I can use in this case?

Edit # 1:

Some additional comments from Fabio are here .

Edit # 2:

Studying further led me to the persist (...) method, which is similar to save (...) but different enough to confuse. This expression, taken from hibernate frequently asked questions , is interesting:

The persist () method also ensures that it does not execute an INSERT if it is called outside the bounds of a transaction. This is useful in lengthy conversations with an extended session / persistence context.

Of course, if he guaranteed the same thing inside the transaction boundary, would it be more useful? I was under the impression that the use of transactions was not approved in any way.

+3
1

- ISession.Save , , , .

, ( ), - , , . , .

+1

Source: https://habr.com/ru/post/1716866/


All Articles