title: Generic Hibernate DAO
body: <p>appreciate it if some one could help on it. </p>
  
  <p>My plan is to have two layers. One is Service layer and second is DAO layer. The service layer will do business logic and DAO layer will do CRUD data operations.</p>
  
  <p>Have two hibernate entities named Person and Order. These two entities implement a BaseEntity interface. Would like to write a generic method in DAO layer, so that it can take any entity.</p>
  
  <p>Any suggestion as how to write that generic dao method?</p>
  
  <pre><code>@Entity
  @Table(name = "PERSON")
  public class Person implements BaseEntity, java.io.Serializable {
  
  private int id;
  private String firstName;
  
  public Person() {
  }
  
  @Id
  @Column(name = "PERSON_ID")
  @GeneratedValue(strategy = GenerationType.AUTO)
  public int getId() {
      return id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  @Column(name = "FIRST_NAME", nullable = false, length = 50)
  public String getFirstName() {
      return firstName;
  }
  
  public void setFirstName(String firstName) {
      this.firstName = firstName;
  }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>@Entity
  @Table(name = "PURCHASE_ORDER")
  public class Order implements BaseEntity java.io.Serializable {
  
  private int id;
  
  public Order() {
  }
  
  @Id
  @Column(name = "ORDER_ID")
  @GeneratedValue(strategy = GenerationType.AUTO)
  public int getId() {
      return id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  @Transient
  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  public Set&lt;OrderItem&gt; getOrderItems() {
      return orderItems;
  }
  
  public void setOrderItems(Set&lt;OrderItem&gt; orderItems) {
      this.orderItems = orderItems;
  }
  }
  </code></pre>
  
  <p>Can you please advise as how to create a generic method which should take either Person or Order entity as input parameter?</p>