title: While loop won't stop looping Java
body: <p>I have created simple table called Reservations and this table have following columns: ID, DUE_DATE, PRODUCTS_PAID, RESERVATION_NAME, SALE, TOTAL_SELL_PRICE and CUSTOMER_ID.</p>
  
  <p>Now what I want to do is that I want to iterate through this table where CUSTOMER_ID is given value. Here is my method that collects all those columns data by CUSTOMER_ID:</p>
  
  <pre><code>   public Collection&lt;Reservations&gt; findReservation(int cuID) {
      EntityManager em = getEntityManager();
      Query q = em.createQuery("SELECT r FROM Reservations r WHERE r.customerData.id = :cID");
      q.setParameter("cID", cuID);
      List results = q.getResultList();
      return results;
  }
  </code></pre>
  
  <p>My problem here is that whenever I run iteration loop it won't stop iterating but it continues to iterate. I have only two rows of data in that table. Can you tell me why this iteration continues and won't stop? Obviously I just want to iterate all data inside of that table based on given CUSTOMER_ID value.</p>
  
  <p>I have tried for loops, for each loops and while loops and non of them works. It must be something to do with my code. Here is one while loop that I tested but it won't stop iteration like the rest loops:</p>
  
  <pre><code>       for(Iterator itr2 = rd.findReservation(cuID).iterator(); itr2.hasNext();){
          rModel.addRow(Arrays.asList(rd.findReservation(cuID).iterator().next().getId(), 
                  rd.findReservation(cuID).iterator().next().getReservationName(),
                  rd.findReservation(cuID).iterator().next().getCustomerData().getCustomerName(),
                  rd.findReservation(cuID).iterator().next().getCustomerData().getCustomerType(),
                  rd.findReservation(cuID).iterator().next().getDueDate(),
                  rd.findReservation(cuID).iterator().next().getTotalSellPrice(),
                  rd.findReservation(cuID).iterator().next().getSale(),
                  rd.findReservation(cuID).iterator().next().getProductsPaid(),
                  "Print"));
      }
  </code></pre>
  
  <p>If you wonder what is cuID, its just an integer value which is received from table column. This value is customerID. It works well. So it shouldn't effect on the code. All help is appreciated :)</p>