Is it possible to suppress an update after pasting in NHibernate?

I was thrown into researching database performance issues with a new application using NHibernate. I noticed that on some tables NH does insert a row, followed by updating the same row with exactly the same data. What I have gathered so far is that updates after inserts are performed in tables that define a one-to-one relationship.

In any case, I would expect NH to indicate that the data is the same and suppresses the additional update. Is there any way to suppress this additional update?

+6
nhibernate
source share
1 answer

It looks like you have a bi-directional one-on-one association.

The solution to this problem is to add inverse="true" on the one-to-many relationship. Here is an example .

Insertion is performed by a child element that saves its data. The update is performed by the parentId parameter of the child record in the database. If the relation was unidirectional, the first insert would not have parentId, and an update would be required. In a bidirectional manner, updating is redundant as you describe. inverse="true" tells parents that the child is responsible for maintaining the relationship, thereby preventing additional updates.

+6
source share

All Articles