title: How to test the hibernate generic dao pattern
body: <p>I'm starting a project using Google Guice and Hibernate and, in the way to configure the database access layer, I got troubled with several doubts along this process.</p>
  
  <p>I'm using JPA annotations in my POJOs and my Generic DAO implementation uses an EntityManager object to communicate with the database. I did several "manual" tests and I saw it was working fine but I prefer to follow a TDD methodology to enforce my knowledge in this kind of methodologies. I'm not sure what is the best way to test generics in java and even less the best solution for testing the Hibernate Generic DAO pattern.</p>
  
  <p>I have read several solutions but I don't feel really comfortable with none of them:</p>
  
  <ul>
  <li>One of them is to make an abstract class to test the Generic DAO and use abstract methods to get the specific DAO and to get the instances to persist, etc.</li>
  <li>Another solution consist on use an abstract class (like the previous solution) and use factories instead of abstract methods: With these two solutions I don't know if it's worth to have a method to get an entity to test every each case in my project.</li>
  <li>Another one solution could be to test every functionality in the specific DAO better than in the generic dao: I think this is the worst solution because, in the most of cases, I will have to repeat a lot of code to test the same thing.</li>
  </ul>
  
  <p>Apart from that, I have read that it could be better to remove the DAO layer and use the entity manager directly from services: I don't think this is the best way because you are mixing the database layer with the service layer.</p>
  
  <p>Anyone who could help me please?!</p>