According to the REST philosophy, a PUT operation must create an entity if it does not exist, or update if this happens. For example, if a client performs this operation:
PUT http://server/user/5?firstname=John&lastname=Doe
I should expect user with id 5 to be created or updated.
The upgrade case is simple in NHibernate; just upload the user and update the first and last name.
However, how do I create a user with identifier 5? By default, NHibernate manages all entity identifiers. Even if you set the identifier yourself, NHibernate will ignore it and replace it with its own. If I switch to using the assigned identifiers, I can assign a new user with identifier 5, but then I will lose many NHibernate functions.
In other words, is there a way to configure NHibernate to use the generated identifier if it is not provided, and to use the user identifier if it is provided? If not, how do I get around this problem of creating a PUT using NHibernate?
source
share