I have a design question about the use of Hibernate annotations and DAO pattern. The DTO are supposed to represent entities of the data model. The DAOs are interfaces that define operations on these DTOs. The DAOs implementations are classes that implement the DAO interfaces, and implement the operations defined by these interfaces (for example using Hibernate/MySQL).
My question is : How can I use Hibernate annotations in this case? If I annotate directly the DTO, I couple my DTO with the Hibernate framework which is a bad practice I think.
Maybe it’s a simple question but the problem is interesting.
Thanks
It’s a matter or supposed “independance” vs. ease of use. Either you choose to use Hibernate or another JPA engine, and you indeed need to have annotations on your entities and have the hibernate jars in your classpath to use them. Or you choose to be completely independant of JPA/Hibernate, but you have to implement the whole persistence yourself.
My opinion is that sacrificing the ease of use and productivity gains offered by JPA just to avoid some jars in the classpath is a bad choice. But YMMV.