The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

flam70 (4) [Avatar] Offline
#1
First, many thanks for your book.

I would like to know the main différence between DAO and repository because i don't realy see the difference. I read a lot about these patterns but i feel a little confused. what is the main difference if one exits.

Second, when i use Spring for declarative transactions, does hibernate session bind with the transaction or not.

Thanks
dgalehouse (7) [Avatar] Offline
#2
Re: DAO and repository
> First, many thanks for your book.
>
> I would like to know the main différence between DAO
> and repository because i don't realy see the
> difference. I read a lot about these patterns but i
> feel a little confused. what is the main difference
> if one exits.

In the book, a repository is a DAO and is used when the logic is organized around a domain model. In the examples, the repositories extend HibernateDaoSupport or JdoDaoSupport. When transaction script-style business logic is used in the book, instead of using repositories, DAOs are used. I think the main difference is that a repository is a first-class member of the domain model and according to the Domain-driven Design book referenced in Pojos in Action, has characteristics beyond those of a simple DAO like accessing only aggregate roots and creating the illusion of an in-memory collection of the objects it's responsible for.
ceracm (113) [Avatar] Offline
#3
Re: DAO and repository
Sorry about the delay in replying.

These are excellent points.

Conceptually, DAOs and repositories play different roles.
A repository represents a collection domain objects in a domain model.
A DAO abstracts and encapsulates access to a persistent store and, as was pointed, out I've used in transaction script based designs.

However, In practice DAOs and repositories usually look very similar.

Having said that there are some folks on the Domain driven design mailing list (http://groups.yahoo.com/group/domaindrivendesign/) who have argued that repositories should call DAOs. Most of the time though, repositories would simply delegate to the DAO and so it would not be worthwhile writing code this way. The exception would be complex queries where, for example, the application retrieves objects from the database and then filters them in memory. In such a situation the Hibernate-specific code could be implemented in a DAO and the generic code in a repository.

I hope this helps.

Chris
flam70 (4) [Avatar] Offline
#4
Re: DAO and repository
Thanks for your answer.
it helps me a lot.