Reputation: 795
I am a little confused about services. Why I must use services for hibernate integration? I think i can use directly DAO interfaces. For example at this tutorial http://www.onlinetechvision.com/?p=566 why he used IUserService instead of IUserDAO. Is IUserService really necessary?
Upvotes: 3
Views: 487
Reputation: 96385
Services are good for several things:
Coordinating DAO operations within a transaction, so if the logic for your action demands multiple SQL calls those can be committed or rolled back together.
Providing a place to put presentation-independent business logic. I have a related answer that talks about what goes into services as opposed to controllers.
Clearly exposing the low-level use case actions that your application supports. In other words, you can tell what things that the user can do in the application by looking at the methods on the service.
If you feel like services are overkill (for instance, you are building a CRUD application with no business logic and no need for combining multiple data access operations in a transaction) then you don't have to use them. You can put transactional annotations on the DAOs.
(Be aware I am not familiar with JSF (used in the tutorial linked to in the question), if there is a JSF-specific angle to this question then I can't address that.)
Check out something like Grails if you are building a CRUD application. It provides all the application configuration out of the box including data access methods that let you avoid coding DAOs, plus it lets you start without services and add them in as you need them.
Upvotes: 6
Reputation: 120848
You inject the interface, not the real implementation(spring injects the correct thing for you). Thus, later if needed, you can change the implementation if needed. This is the simple explanation, I am sure more comlicated will follow shortly.
Upvotes: 1