Service difference, repositories and controller

Asked

Viewed 5,896 times

2

What’s the difference between services, repositories and controller in JPA.

I know the repositories work with data abstraction. Who takes the database data?

Mapped classes (@Entity), controller and service?

  • 1

    JPA does not have these artifacts (services, repositories and controllers). Specify a context where they exist to scope the answer.

  • As mentioned in the previous answer, JPA does not have this architecture by default. However, if you implemented it, the default is as follows: The Controller is responsible for the logic of services, consuming the methods of the Service. Service is responsible for calling operations with the bank, while Repositories house their inserts/queries/updates/removals.

  • @Caffé Implementei com spring mvc spring data e spring security.

  • @Nikofoxxx ?

  • Here in my project, the service is responsible for calling the Repository methods and assembling the objects needed to return to the Controller. Repository is where, for example, SQL queries are located. Understand?

1 answer

7


As already said, JPA is only the technology of access to the database. With it you can use Design Patterns (design pattern) that are not part of JPA specifically.

Repository is a Design Pattern where data is obtained from the database and also occurs the business rule. This returns domain objects that would be Entities (classes annotated with @Entity).

DAO is another Design Pattern where there is only communication with the database without business rule.

Service would be another Desing Pattern where there is only business rule and does not have direct access to the database.

Controller It is used to handle the connection of the View to the other parts of the system that are the rule of business and database.


When developing a system you will choose which you will use. It can be Entity + DAO + Service, Entity + Repository, using an Object being Entity and Repository at the same time. Both cases connected with the view via the Controller.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.