What's the difference beetwen EntityManager and DAO?

1.8k views Asked by At

What's the difference beetwen EntityManager and DAO? Is it same thing?

1

There are 1 answers

0
JB Nizet On BEST ANSWER

EntityManager is an interface provided by JPA, which provides generic methods used to persist, merge, find and create queries for entities.

DAO is a pattern used to isolate database-access code in a separate component (the DAO) so that services concentrate on the business logic rather than low-level database stuff. It helps in unit-testing the service, and in separating responsibilities.

When using JPA, you typically write one DAO per entity, that will contain all the JPA code (queries, mostly) related to that entity. And this DAO uses the EntityManager.