I'm writing an N-tier application that uses NHibernate and a Repository pattern to interface with a SQL store. Because the project is N-Tier, the NHibernate entities are mapped to the domain model who are then mapped to view models, and vice versa, causing models to be disconnected between NHB sessions.
The problem I have is that when I attempt to save a changed entity (an entity that has been recently instantiated to represent an old, changed entity from a previous session) using the Merge() method, I get an exception about violating a unique index on my table because NHB is trying to insert instead of update a row with the same ID as the entity. I've double checked my mappings, and that my entity contains all the right values in all the right places... it would seem NHB is not checking if a row exists before trying to insert, thoughts?