Take the 2-minute tour ×

In the repository layer I define normal data operations such as inserting, finding and so on. I am using Spring and I have the @Repository annotation above the class. Is it bad to use this class directly in the @Controller class for instance? Should all repositories always have a service layer that just delegate to the repository layer?

share|improve this question
add comment

2 Answers

It totally depends on your choice. In Spring Roo, you don't just skip the Repository or Service layer, but use a Rich Domain Model where you have the data access logic in the domain itself. Frameworks like Groovy on Grails use a single Repository layer. So i think its OK to use it directly in the Controller.

share|improve this answer
add comment

I similarly asked what use are EJBs? An answer said this:

your [service layer] typically orchestrates application of business logic but more often than not does not actually perform it, it is usually a very thin wrapper.

The service-layer methods can define the operations that are transactions, and which therefore have annotations to get AOP transaction support added automatically for you. See also an answer to a related question, which says:

Spring's idiom would recommend having a service interface that knows about units of work and a persistence interface that deals with relational databases. The methods in the service interface should map closely to your use cases. The service implementation knows about all the model and persistence packages and classes it needs to accomplish the goals of the use case.

share|improve this answer
add comment

Your Answer


