title: ArrayList displaying only the last value of index
body: <pre><code>public ArrayList getEmpInfo(int id) {
  
          ArrayList data = new ArrayList();
          loginPojo lp=new loginPojo();
          EmployeeInfoPojo emp_info = new EmployeeInfoPojo();
  
          Session session = null;
          SessionFactory sessionfactory = new Configuration().configure().buildSessionFactory();
  
          session = sessionfactory.openSession();
  
          String sql_query = "from loginPojo where id!=" + id;
          Query query = session.createQuery(sql_query);
  
          List&lt;loginPojo&gt; list = query.list();
  
          Iterator it = list.iterator();
  
          while (it.hasNext()) {
              lp = (loginPojo) it.next();
              emp_info.setName(lp.getName());
  
              System.out.println("Before "+emp_info.getName());
              data.add(emp_info);
              System.out.println("After "+emp_info.getName());
          }
          return data;
      }
  </code></pre>
  
  <p>This is the code for getting the information from the database using the hibernate framework.I tried to display the ArrayList in the main using the following code.</p>
  
  <pre><code>  public static void main(String args[]) {
      EmployeeInfoPojo emip = null;
      EmployeeInfo emi = new EmployeeInfo();
      ArrayList info = emi.getEmpInfo(102);
  
      Iterator it = info.iterator();
  
      while (it.hasNext()) {
          emip = (EmployeeInfoPojo) it.next();
          System.out.println(emip.getName());
      }
  }
  </code></pre>
  
  <p>The output Expected is:
  John
  Jose
  Mark</p>
  
  <p>But what am getting is:
  Mark
  Mark
  Mark</p>
  
  <p>Can anyone find me what's wrong with the code????</p>