Handling Unique Key Constraints in NHibernate

632 views
Skip to first unread message

Mike

unread,
Sep 1, 2010, 12:34:16 PM9/1/10
to nhusers
Hello,
Can somebody point me in the correct direction on how to handle unique
key constraint violations in NHibernate? Is there a more optimized
way than simply querying the table before attempting the insert/
update?

Thanks!

Jason Meckley

unread,
Sep 1, 2010, 1:42:44 PM9/1/10
to nhusers
the uniqueness exists at the database level, therefore you need to go
to the database to check.

If you can generally assume the object is unique, then you could
bypass the check, catch the unique constraint violation exception and
ask the user to submit their request again.

Mike

unread,
Sep 1, 2010, 1:54:33 PM9/1/10
to nhusers
OK. Wasn't sure if NHibernate had any facilities to handle this
without having to catch an exception.
Reply all
Reply to author
Forward
0 new messages