I have what I think is a rather common use case for NHibernate. I create an entity and try to save it using ISession.Save() followed by a Transaction.Commit(). At this point, I expect violations of things like unique/primary key constraints to come up to me as exceptions. What I'm seeing, however, is just a GenericADOException. This doesn't help me differentiate between genuine DB failures versus things like asking the user to choose another name for the entity to preserve uniqueness.
At the moment, I've implemented the ugly workaround of querying first to ensure that the constraints won't be violated. This is just a race condition waiting to happen and I really don't want users to see "Oops, the DB did something funny! Maybe you should try this again." kind of messages.
Is there an elegant way to fix this?