These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Business logic best practice question for ASP.Net
PostPosted: Fri Feb 13, 2009 11:32 am 
Newbie

Joined: Thu May 26, 2005 4:50 pm
Posts: 7
I have a best-practice question. I'm using NHiberate 2.0.1 with Burrow and ASP.NET.

Say I have a User domain class that has a rule that no two users with the same username may exist. To enforce this in the database I add a unique constraint to the "username" column. I realize that I need to enforce this in my business logic as well.

What are some valid ways this can be handled? I've considered:

1. Injecting a DAO instance into User objects and having them call a DAO method that checks for an existing User with the same username. I assume a problem here is the off chance of a race condition where the DAO checks for a duplicate, doesn't find one, and then before the database update happens, someone else inserts a User with that name.

2. Catching the exception raised by NHiberate when the database constraint is violated. My problem with this approach is since Burrow is flushing the session at the end of the HTTP request, the only option I think I have is to catch it in the global exception handler for the web application and redirect to an error page. I won't be able to give any specific error message on the page they were working with. Also, some of my business logic is now expressed in my web application not in my domain.

In addition, is it normal/acceptable to enforce business logic that requires looking at the database in a domain class itself like in option 1?

Thanks for any help, ideas, or shoves in the right direction.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.