should dao objects be directly used inside controller

I have the following code inside my controller :
 @RequestMapping(value = "/snippets/{id}/edit", method = RequestMethod.GET)
    public ModelAndView editSnippet(@PathVariable String id) {
        Snippet snippet = snippetDao.getSnippetById(id);
        ModelAndView mav = new ModelAndView("edit");
        mav.addObject("snippet", snippet);
        return mav;

Open in new window

consider the line :        Snippet snippet = snippetDao.getSnippetById(id);
I saw in some code that people use somekind of say snippetManager to deal with Dao and avoid writing dao lines directly inside the controller.
Dont know whether this is correct ?
Please throw some light
1) is it ok to use dao objects directly inside a controller or there are better approaches ?

Rohit BajajAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I've seen both approaches used.

DAO's would contain persistence logic and nothing more. But there are cases where you need to use an intermediate layer like a service layer to augment the data returned to the application layer.
For example, once you get the snippet object back, you need to process it further in the service layer by making a SOAP web service call etc before returning to application controller.

The service layer is responsible for business logic. It can act as a facade where you invoke a coarse grained method call on the service and it delegates to multiple DAO's. You can then define the scope of your transactional boundary around the service rather than all the individual DAOs.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mccarlIT Business Systems Analyst / Software DeveloperCommented:
In a simple case like this, the extra layer wouldn't add any benefit, so just keep with what you have. If your controller method ended up getting more complex, then there may be scope for adding the extra Manager/Service layer.

BTW, there's no right or wrong answer because every situation is different.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.