My 2 cents:

It depends on the business logic relevent to that data set.

If a data set is read only and always expected in the system, there may be a
case to throw an exception in the data layer. This would also be useful if
other objects or DAO's may make nested calls on that specific DAO as part of
their own call.

Most situations would be suited to returning null for an empty result set.
As long as your service layer was aware that null values are possible and
then handle accordingly. If you wanted to be really safe, you could return
an empty list which would avoid NullPointerExceptions at the service layer.
The service layer still has the oppurtunity to check for empty result sets
and throw an exception if this doesnt fit the business logic.


On 11/12/06, Sanjiv Jivan <[EMAIL PROTECTED]> wrote:

"so, at MVC ,  I assume u will still check if  Item=null, show error at
view , etc. , right?"

That's what I do. I don't throw an exception if no record is found. I
simply pass it all the way to the controller where its handled.



On 12/11/06, Man-Chi Leung <[EMAIL PROTECTED]> wrote:
>
> thanks for you sharing,
>
> quick check. when u return null to  our service layer, did u rewrap
> with dataNotFoundException ? or returning null all the way back to MVC?
>
> so, at MVC ,  I assume u will still check if  Item=null, show error at
> view , etc. , right?
>
>
> I am just wondering, all the work on catching and throwing and
> validating with if & else, scattering at different layers,
> hm.. shouldn't be a better way to do it?  ....
>
> ~thinkboy.
>
>
>
> On 2006-12-11 14:17:00 +0800, "Sanjiv Jivan"
> <[EMAIL PROTECTED]> said:
>
> >
> > Here's how I handle it :
> >
> > import org.springframework.dao.support.DataAccessUtils;
> >
> > public Item getItemByName(String name) {
> >         List results = getHibernateTemplate().find("from Item where
> name=?",
> > name);
> >         return (Item) DataAccessUtils.uniqueResult(results);
> > }
> > The source of DataAccessUtils.uniqueResult is below. As you can see,
> it
> > returns null if the collection size is 0 and if the size is greater
> then 1,
> > it throws an exception as
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to