NHibernate - prohibit deletion on a specific object (i.e. do read only)

How can I prevent NHibernate from deleting a single object of a particular class? The programmatic method that I am currently using includes checking the unique field of the entity "Name".

Here is the scenario: I have a person and a group. A group can have people and other groups. If a group with the name β€œAdmins” is trying to delete, it will not be due to restrictions on the level of transactions that I use (in particular, to check the column / field β€œName”), because it is unique). So good.

But now I think that if another group is created, and the "Admins" become a subgroup of this, the verification will fail. This will mean the removal of "admins." Therefore, I am looking for a better way than to cross the parent / child containment tree, for example. using NHibernate

I cannot use a class constraint such as "class Mutable = false", I mean a read-only constraint for one or two separate objects of a particular class.

Hi,

_NT

+4
source share
1 answer

You can write your own implementation of IPreDeleteEventListener and connect to the nhibernate event system to programmatically stop and delete the object.

This is an example of using listeners.

+3
source

All Articles