title: greenDAO: Double in entity is saved with value 0
body: <p>I am inserting a <code>List&lt;entity&gt;</code> in database. This entity has one <code>Double</code> field.
  The List have 49 elements, but, when I load it from database, in +-80% of them the value of the double is 0.</p>
  
  <p>Entity class:</p>
  
  <pre><code>public class NumeroStats implements IStats {
  
      private Long id;
      private Integer numero;
      private Integer sorties;
      private java.util.Date derniereSortie;
      private Double percentage;
  
      //Ommited gets &amp; sets
  }
  </code></pre>
  
  <p>The insertion code:</p>
  
  <pre><code>for (NumeroStats ns : stats.getNumerosStats()) {
      ns.setPercentage((ns.getSorties() * 1.0 / drawCount) * 100);
      Log.d(TAG, "Pre Insert NumeroStats: " + ns.getNumero() + " % " + ns.getPercentage());
      long id = nsDao.insert(ns);
      NumeroStats asd =  nsDao.load(id);
      Log.d(TAG, "Inserted NumeroStats: " + asd.getNumero() + " % " + asd.getPercentage());
  }
  </code></pre>
  
  <p><code>drawCount=844</code>, and always <code>&gt; 0</code>
  Before inserting the entities, all values are correct.
  After insert each <code>NumberStats</code> and load it from it's id, the values are correct.</p>
  
  <p>But when I load them in one fragment the most part of items with <code>percentage=0</code>.</p>
  
  <p>The load code in fragment:</p>
  
  <pre><code>NumeroStatsDao nsDao = mDaoSession.getNumeroStatsDao();
  List&lt;NumeroStats&gt; nStatsList = nsDao.queryBuilder().where(NumeroStatsDao.Properties.Numero.notEq(0)).list();
  </code></pre>
  
  <p>SQLite Editor shows that the values stored in database with the wrong percentage values, all other fields are correct.</p>
  
  <p>There is no null variables, I've double checked the <code>NumberStatsDao</code> class and all looks correct (it was generated with greenDAO generator).</p>
  
  <p>The NumberStatsDao class:</p>
  
  <pre><code>public class NumeroStatsDao extends AbstractDao&lt;NumeroStats, Long&gt; {
  
      public static final String TABLENAME = "NUMERO_STATS";
  
      /**
       * Properties of entity NumeroStats.&lt;br/&gt;
       * Can be used for QueryBuilder and for referencing column names.
       */
      public static class Properties {
          public final static Property Id = new Property(0, Long.class, "id", true, "_id");
          public final static Property Numero = new Property(1, Integer.class, "numero", false, "NUMERO");
          public final static Property Sorties = new Property(2, Integer.class, "sorties", false, "SORTIES");
          public final static Property DerniereSortie = new Property(3, java.util.Date.class, "derniereSortie", false, "DERNIERE_SORTIE");
          public final static Property Percentage = new Property(4, Double.class, "percentage", false, "PERCENTAGE");
      };
  
  
      public NumeroStatsDao(DaoConfig config) {
          super(config);
      }
  
      public NumeroStatsDao(DaoConfig config, DaoSession daoSession) {
          super(config, daoSession);
      }
  
      /**
       * Creates the underlying database table.
       */
      public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
          String constraint = ifNotExists? "IF NOT EXISTS ": "";
          db.execSQL("CREATE TABLE " + constraint + "'NUMERO_STATS' (" + //
                  "'_id' INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                  "'NUMERO' INTEGER," + // 1: numero
                  "'SORTIES' INTEGER," + // 2: sorties
                  "'DERNIERE_SORTIE' INTEGER," + // 3: derniereSortie
                  "'PERCENTAGE' REAL);"); // 4: percentage
      }
  
      /**
       * Drops the underlying database table.
       */
      public static void dropTable(SQLiteDatabase db, boolean ifExists) {
          String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'NUMERO_STATS'";
          db.execSQL(sql);
      }
  
      /**
       * @inheritdoc
       */
      @Override
      protected void bindValues(SQLiteStatement stmt, NumeroStats entity) {
          stmt.clearBindings();
  
          Long id = entity.getId();
          if (id != null) {
              stmt.bindLong(1, id);
          }
  
          Integer numero = entity.getNumero();
          if (numero != null) {
              stmt.bindLong(2, numero);
          }
  
          Integer sorties = entity.getSorties();
          if (sorties != null) {
              stmt.bindLong(3, sorties);
          }
  
          java.util.Date derniereSortie = entity.getDerniereSortie();
          if (derniereSortie != null) {
              stmt.bindLong(4, derniereSortie.getTime());
          }
  
          Double percentage = entity.getPercentage();
          if (percentage != null) {
              stmt.bindDouble(5, percentage);
          }
      }
  
      /**
       * @inheritdoc
       */
      @Override
      public Long readKey(Cursor cursor, int offset) {
          return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
      }
  
      /** @inheritdoc */
      @Override
      public NumeroStats readEntity(Cursor cursor, int offset) {
          NumeroStats entity = new NumeroStats( //
                  cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
                  cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1), // numero
                  cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // sorties
                  cursor.isNull(offset + 3) ? null : new java.util.Date(cursor.getLong(offset + 3)), // derniereSortie
                  cursor.isNull(offset + 4) ? null : cursor.getDouble(offset + 4) // percentage
          );
          return entity;
      }
  
      /** @inheritdoc */
      @Override
      public void readEntity(Cursor cursor, NumeroStats entity, int offset) {
          entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
          entity.setNumero(cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1));
          entity.setSorties(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
          entity.setDerniereSortie(cursor.isNull(offset + 3) ? null : new java.util.Date(cursor.getLong(offset + 3)));
          entity.setPercentage(cursor.isNull(offset + 4) ? null : cursor.getDouble(offset + 4));
      }
  
      /**
       * @inheritdoc
       */
      @Override
      protected Long updateKeyAfterInsert(NumeroStats entity, long rowId) {
          entity.setId(rowId);
          return rowId;
      }
  
      /**
       * @inheritdoc
       */
      @Override
      public Long getKey(NumeroStats entity) {
          if (entity != null) {
              return entity.getId();
          } else {
              return null;
          }
      }
  
      /**
       * @inheritdoc
       */
      @Override
      protected boolean isEntityUpdateable() {
          return true;
      }
  
  }
  </code></pre>
  
  <p>EDIT: If I set the percentage to 1.0, the same is happening.</p>
  
  <pre><code>ns.setPercentage(1.0);
  </code></pre>
  
  <p>EDIT2: Inserting the entities as below code, all percentages are stored with the random values and always <code>!= 0</code>.</p>
  
  <pre><code>NumeroStatsDao nsDao = mDaoSession.getNumeroStatsDao();
  
  List&lt;NumeroStats&gt; nsList = new ArrayList&lt;NumeroStats&gt;();
  
  for(int i = 0 ; i &lt;50 ; i++){
      nsList.add(new NumeroStats(null, i+1, i*3,new Date(), new Random().nextDouble()*100));
  }
  
  nsDao.insertInTx(nsList);
  </code></pre>
  
  <p>This looks very awkward. I've tried to insert an new instance of <code>NumeroStats</code> inside the insertion loop, but with no success, great part of the double values are still 0.</p>
  
  <pre><code>nsDao.insert(new NumeroStats (null, ns.getNumero(),ns.getSorties(), ns.getDerniereSortie(), (ns.getSorties() * 1.0 / drawCount) * 100));
  </code></pre>
  
  <p><strong>EDIT 3:
  I've found the cause of problem, but I can't find any reasonable explanation why it happens.</strong></p>
  
  <p>Before I insert the List the <code>NumberStats</code>, I insert one <code>NumberStats</code> with <code>numero = 0</code> and <code>sorties = 844</code>, the drawcount value. (It's a bad way to do this, I know).</p>
  
  <p>Like this:</p>
  
  <pre><code>NumeroStats nsDrawCount = new NumeroStats();
  nsDrawCount.setNumero(0);
  nsDrawCount.setSorties(drawCount);
  
  nsDao.insert(nsDrawCount);
  
  for (NumeroStats ns : nsList) {
      ns.setPercentage((ns.getSorties() * 1.0 / drawCount) * 100);
      nsDao.insert(ns);
  }
  </code></pre>
  
  <p>If I don't insert the <code>nsDrawCount</code>, the values inserted in the loop are correct.
  I've tried the initialize and insert the <code>nsDrawCount</code> after the loop insertion, and after that the sorties values are stored with the 0 value too.</p>
  
  <p>That's weird, isn't it? What could make it behaves like that?</p>