According to REST philosophy, a PUT
operation should (taken from Wikipedia):
PUT http://example.com/resources/142
Update the address member of the collection, or if it doesn't exist, create it.
NHibernate seems to have two ways of dealing with entity IDs:
- Auto-generate an ID, regardless of what value the user set.
- Use the ID assigned by the user, but lose all auto-generation capabilities.
The problem here with a PUT
operation is the part about creating the entity if it doesn't exist. My assumption is that if you PUT
a resource that doesn't exist, it will create it with the same ID as specified by the URL (such as 142 if we use the above example). However, NHibernate doesn't allow you to set the ID if it's auto-generated.
So my question is, is there a way to get NHibernate to auto-generate an ID if the entity doesn't have one (or has the default value for the ID type, for example 0 for ints), but also save the entity with the ID that the user set?