title: Hibernate not getting correct records using query.list();
body: <p>I'm building an application that uses <code>Hibernate</code> and <code>Mysql</code>, My entire databse has <code>15</code> tables. </p>
  
  <p>Here is the problem: I start inserting records into the database and viewing them using <code>query.list();</code> to get the added records, howerver after a while of getting "correct" results, I start not having the last record I added, I add again and it's the same(the one that was showing before shows but not the last one I added), I refresh and I get the right records, I refresh again and I get <code>32</code> records instead of <code>43</code>, I'm not using any complicated queries just a <code>Select</code> with a condition, as you can see this is really weird.</p>
  
  <p>Note that I'm saving the objects and then imidiately fetching, so an insert directly followed by a select(I don't know if that can cause problems in Mysql), the records are also added into the databse perfectly, using <code>Mysql workbench</code> I can see that my records are added corretly into the database, I really hope someone can atleast help me debug this, because I'm not getting any errors.</p>
  
  <p>I'm using Hibernate <code>4.3.10</code> and java version <code>1.8.0_131</code></p>
  
  <p>Here is a piece of code that "sometimes" gives me problems when getting the results from one of the entities that I use:</p>
  
  <p>getting a list of <strong>Products</strong>:</p>
  
  <pre><code>public static List&lt;Product&gt; productsList() {
          //singleton factory object
          SessionsGenerator FactoryObject = new SessionsGenerator();
          Session session = SessionsGenerator.getFactory().openSession();
          List&lt;Product&gt; list = new ArrayList&lt;&gt;();
          try {
              list = session.createQuery("from Product where deleted= false").list();
              System.out.println("-------------- list product: "+list); // testing from console here I get the same results on the user interface, so it can't be a Javafx problem.
          } finally {
              session.close();
          }
          return list;
      }
  </code></pre>
  
  <p>Code for inserting a product:</p>
  
  <pre><code>public static boolean SaveOrUpdate(Product product) {
          SessionsGenerator FactoryObject = new SessionsGenerator();
          Session session = SessionsGenerator.getFactory().openSession();
          try {
              session.beginTransaction();
              session.saveOrUpdate(product);
              session.getTransaction().commit();
          } catch (Exception e) {
              return false;
          } finally {
              session.close();
              return true;
          }
      }
  </code></pre>
  
  <p>Here is the Product entity class:</p>
  
  <pre><code>@Entity
  @Table(name = "Product")
  public class Product{
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "id", nullable = false)
      int id;
      @Column(name = "code", nullable = false)
      String code;
      @Column(name = "matricule", nullable = false)
      String matricule;
      @Column(name = "marque", nullable = false)
      String marque;
      @Column(name = "type", nullable = false)
      String type;
      @OneToMany(targetEntity = Facture.class, mappedBy = "product", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      private List&lt;Facture&gt; factures;
      @OneToMany(targetEntity = Achat.class, mappedBy = "product", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      private List&lt;Achat&gt; achats;
      @Column(name = "deleted", nullable = false)
      boolean deleted;
  
      public Product() {
      }
  
      public Product(String code, String matricule, String marque,String type) {
          this.code = code;
          this.matricule = matricule;
          this.marque = marque;
          this.type = type;
          this.deleted = false;
      }
  //setters and getters
  </code></pre>
  
  <p>Here is my hibernate configuration file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
    &lt;session-factory&gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQL5Dialect&lt;/property&gt;
      &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
      &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
      &lt;property name="hibernate.connection.password"&gt;root&lt;/property&gt;
      &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/gestioncommerciale&lt;/property&gt;
      &lt;property name="connection_pool_size"&gt;1&lt;/property&gt;
      &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
      &lt;property name="hibernate.current_session_context_class"&gt;thread&lt;/property&gt;
    &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Edit: I tried <code>session.flush()</code> and <code>session.clear()</code>, cause I though the problem has to do with cashing, but I still have the same problem, I'm starting to think this is a problem with the <code>Mysql Workbench</code> server.</p>
  
  <p>It has been five days, I can't believe no one in the entire stackoverflow community even has the slightest idea about this, this is as strange as the problem I'm having. </p>