Java EE Architecture - Are DAO's still recommended when using an ORM like JPA 2?

前端 未结 2 1992
醉梦人生
醉梦人生 2020-11-30 18:21

If I\'m using an ORM like JPA2 - where I have my entities that are mapped to my database, should I still be using a DAO? It seems like a lot more overhead.

For examp

2条回答
  •  遥遥无期
    2020-11-30 19:18

    For the record.

    For Single responsibility principle (SRP), DAO is a must have, it separates the model and logic in a persistence layer that can be easily portable.

    If a project is using Test Unit then DAO helps to test it correctly (mockup, database testing and so on).

    DAO is a SERVICE and like one, we could wrap our process in a nicely class that is easy to maintenance.

    JPA reduces the number of lines of codes but, nothing more, the old rules still applies.

    JPA brings a repository layer but its not OUR repository layer. In the same principle, let's say that we encapsulated a logic that obtain the profit of some process. May be the encapsulation is simply a multiplication for 0.1 but its still worthy to encapsulate.

    For example, let's say that i have the next problem : for some odd reason, i can insert a new Client in the database?. Where should i start to test?. a: ClientDao if exists, if not, then good luck finding elsewhere.

提交回复
热议问题