title: Resolving Java.lang.ClassCastException
body: <p>I am quite new in hibernate. I am really stuck in <code>Java.lang.ClassCastException</code>problem. Cant resolve this problem of my below code for whole day. Can any on help me please?</p>
  
  <pre><code>@Override
  public ObservableList&lt;Product&gt; getSold() {
      ObservableList&lt;Product&gt; list = FXCollections.observableArrayList();
      Transaction tx=null;
  
      session = Hibutil.getSessionFactory().getCurrentSession();
      try {
          tx= session.beginTransaction();
          List&lt;Product&gt; productList = session.createQuery(" select productName, count(productName) as totalSold  from Product where sell='1' group by productName Order by totalSold desc").setCacheable(true).list();
          tx.commit();
          productList.stream().forEach(list::add);// getting error here
  
          System.out.println(list.get(0));
          return list;
      } catch(HibernateException e) {
          if(tx!=null)tx.rollback();
          return null;
      }
  </code></pre>
  
  <p>I have read <a href="https://stackoverflow.com/questions/3511169/java-lang-classcastexception">this</a> but can'tresolve this problem.</p>