0

I am new to repositories and I am a bit confused at the moment. From what I have read, DAO pattern is where you provide methods to access the the data store. Though, with repository, you access the datastore with an object repo.

I saw two examples here:

https://medium.com/@gustavo.ponce.ch/spring-boot-spring-mvc-spring-security-mysql-a5d8545d837d

http://javainsimpleway.com/spring-mvc-with-hibernate-crud-example/

The first example extends JpaRepository as intended, and no implementations are available (for add, remove, etc).

The second example provides DAO access with methods, though it goes with service/repository implementation. I mean it uses @Repository and @Service even though it is DAO.

Which one is the right implementation handling repositories.

Thanks for your time.

jamana
  • 11
  • 1
  • 4
  • Does this answer your question? [What is the difference between DAO and Repository patterns?](https://stackoverflow.com/questions/8550124/what-is-the-difference-between-dao-and-repository-patterns) – Mayank Tripathi Jan 26 '20 at 13:21
  • No, it does not. I have used that link to understand the difference between DAO and repo patterns among other links. Though, the second example above confuses me. I want to know how DAO implements service/repository. – jamana Jan 26 '20 at 13:24
  • `@Repository` and `@Service` are specializations of `@Component` annotation. Its use basically indicates the purpose of that component and api references gives details on the specifics. – R.G Jan 26 '20 at 13:43

1 Answers1

2

I recommend reading this article.

A DAO is much closer to the underlying storage , it's really data centric. That's why in many cases you'll have DAOs matching db tables or views 1 on 1.

A repository sits at a higher level. It deals with data too and hides queries and all that but, a repository deals with** business/domain objects**.

Jalil.Jarjanazy
  • 839
  • 1
  • 9
  • 22
  • I appreciate you taking the time to reply. Though, my question is not about the difference between repositories and DAO. My question is simple. Why does the DAO implementation on the second link use repository/service while that is the essence of using the repository pattern. – jamana Jan 28 '20 at 13:06