title: Generic DAO design-pattern with inheritance. is this a good design?
body: <p>I just want to have a comment for what I've learned from dozens of samples about Generic DAO design-pattern. I added an inheritance hierarchy between POJO classes, DAO interfaces, and DAO implementations please see codes below</p>
  
  <p><strong>Legend:</strong> </p>
  
  <p><strong>DAOs (From Parent to children)</strong></p>
  
  <p><strong>DAO implementations (From Parent to Children)</strong></p>
  
  <p><strong>POJO classes (From Parent to Children)</strong></p>
  
  <p><strong>The Data Acess Objects (Interfaces)</strong></p>
  
  <p><em>The GenericDAO interface</em></p>
  
  <pre><code>public interface GenericDAO&lt;T&gt; {
     ... some crud operations common to all objets
  } 
  </code></pre>
  
  <p><em>The PersonDAO interface</em></p>
  
  <pre><code>public interface PersonDAO&lt;T extends Person&gt; extends GenericDAO&lt;T&gt; {
     ... some operations unique to a person
  }
  </code></pre>
  
  <p><em>The StudentDAO interface</em></p>
  
  <pre><code>public interface StudentDAO extends PersonDAO&lt;Student&gt; {
     ... some operations unique to a student
  }
  </code></pre>
  
  <p><strong>The Implementations</strong></p>
  
  <p><em>The GenericDAO Implementation</em></p>
  
  <pre><code>@Repository("genericDAO")
  public class GenericDAOImpl&lt;T extends Person&gt; implements GenericDAO&lt;T&gt; {
  
  private Class&lt;T&gt; type;
  
  @SuppressWarnings("unchecked")
  public GenericDAOImpl() {
  
      this.type = (Class&lt;T&gt;) GenericTypeResolver.resolveTypeArgument(getClass(), GenericDAO.class);
      System.out.println(type);
  }
  
  @Resource(name = "sessionFactory")
  protected SessionFactory sessionFactory;
  
  @Transactional
  @Override
  public Integer save(T entity) {
      return (Integer) sessionFactory.getCurrentSession().save(entity);
  }
  
  @SuppressWarnings("unchecked")
  @Transactional
  @Override
  public T get(Integer id) {
  
      return (T) sessionFactory.getCurrentSession().get(type, id);
  }
  </code></pre>
  
  <p>}</p>
  
  <p><em>The PersonDAO implementation</em></p>
  
  <pre><code> @Repository ("personDAO")
   public class PersonDAOImpl&lt;T extends Person&gt; extends GenericDAOImpl&lt;T&gt; implements PersonDAO&lt;T&gt; {
  
        .. implemented methods for person
   }
  </code></pre>
  
  <p><em>The StudentDAO implementation</em></p>
  
  <pre><code> @Repository("studentDAO")
   public class StudentDAOImpl extends PersonDAOImpl&lt;Student&gt; implements StudentDAO {
         .. implemented methods for student
   }
  </code></pre>
  
  <p><strong>The POJO Classes</strong> (Hibernate Annotated)</p>
  
  <p><em>The Person Class (Parent Abstract Class)</em></p>
  
  <pre><code>@MappedSuperclass
  public abstract class Person {
  
  @Id
  @GeneratedValue
  @Column (name = "id")
  private int id;
  
  @Column (name = "name")
  private String name;
  
  @Column (name = "age")
  private int age;
  
  public int getId() {
      return id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  public int getAge() {
      return age;
  }
  
  public void setAge(int age) {
      this.age = age;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  }
  </code></pre>
  
  <p><em>The concrete class (Student)</em></p>
  
  <pre><code>@Entity
  @Table(name = "STUDENT")
  public class Student extends Person {
  
  @Column(name = "school")
  private String school;
  
  public Student() {
  }
  
  public Student(String school) {
      this.school = school;
  }
  
  public String getSchool() {
      return school;
  }
  
  public void setSchool(String school) {
      this.school = school;
  }
  }
  </code></pre>
  
  <p>I've been thinking about how am I going to construct a design-pattern between POJOs and DAO objects for days, Until I've come up with these design based on everything I've learned from different resources around the web. I've come up with the idea of DAO and DAO implementation inheritance based on the inheritance of the POJOs. </p>
  
  <ol>
  <li>is this a good practice? reflecting the hierarchy of the POJOs and do it in DAOs?</li>
  <li>am I doing something wrong about here with my design? because I have a complete program that 
  saves and retrieves my objects from the database without any problem</li>
  </ol>
  
  <p>I'm open to any suggestion or corrections. Thank you in advance!!! </p>