Symfony2 saving wrong data
===

I'm having a headache saving multiple records

I made an algorithm that creates an array of values, then I loop through the array and save the updated data x,y. But for some unknow reason out of the 15 or so values I expect with y = 0; only 1-5 shows as I expect.

Here is my code:
    
    foreach($line as $row){
      if(array_key_exists('id',$row)){
        $region = $em->getRepository("Bundle:Something\\Region")
                ->find($row['id']);
        if (!$region) {
          throw $this->createNotFoundException('No product found for id '.$row['id']);
        }

        $region->setX($row['posX']);
        $region->setY($row['posY']);
        if($row['posY'] == 0){
          error_log("se agrego id: " . $row['id'] . " con y: " . $row['posY']);
          error_log("id actual: " . $region->getId() . "con y: " . $region->getY());
        }
        em->persist($region);
        $em->flush();
        $em->clear();
        unset($region);

here is my output

    se agrego id: 1508 con y: 0
    id actual: 1508con y: 0
    se agrego id: 1931 con y: 0
    id actual: 1931con y: 0
    se agrego id: 1754 con y: 0
    id actual: 1754con y: 0
    se agrego id: 1907 con y: 0
    id actual: 1907con y: 0
    se agrego id: 1641 con y: 0
    id actual: 1641con y: 0
    se agrego id: 1677 con y: 0
    id actual: 1677con y: 0
    se agrego id: 1692 con y: 0
    id actual: 1692con y: 0
    se agrego id: 1578 con y: 0
    id actual: 1578con y: 0
    se agrego id: 1326 con y: 0
    id actual: 1326con y: 0
    se agrego id: 1636 con y: 0
    id actual: 1636con y: 0
    se agrego id: 1637 con y: 0
    id actual: 1637con y: 0
    se agrego id: 1359 con y: 0
    id actual: 1359con y: 0
    se agrego id: 1892 con y: 0
    id actual: 1892con y: 0
    se agrego id: 1324 con y: 0
    id actual: 1324con y: 0
    se agrego id: 1773 con y: 0
    id actual: 1773con y: 0
    se agrego id: 1581 con y: 0
    id actual: 1581con y: 0
    se agrego id: 1538 con y: 0
    id actual: 1538con y: 0
    se agrego id: 1745 con y: 0
    id actual: 1745con y: 0
    se agrego id: 1925 con y: 0
    id actual: 1925con y: 0
    se agrego id: 1564 con y: 0
    id actual: 1564con y: 0
    se agrego id: 1648 con y: 0
    id actual: 1648con y: 0


everything seems to be normal before persisting and flushing

but then i check the database and i see this

    select * from regions where y = 0;
    id  | field | field |  x  | y | field | field |       field       | field  | field |      createdat      |      updatedat      | field 
    ------+---------+---------+-----+---+-------+--------+-------------------+---------+----       ----+---------------------+---------------------+--------------
     1324 |       1 |      58 | 640 | 0 |    24 |     24 | 4fe49d9fddebb.jpg | running |        2 | 2012-06-22 10:29:01 | 2012-07-23 12:13:01 |          118
     1677 |       1 |      58 | 280 | 0 |    40 |     40 | 4fe4e48693650.png | running |       1 | 2012-06-22 15:31:11 | 2012-07-23 12:13:01 |          342
     1508 |       1 |      58 |   0 | 0 |    48 |     16 | 4fe4bfcf58560.jpg | running |      1 | 2012-06-22 12:54:43 | 2012-07-23 12:13:01 |          212
     1565 |       1 |      58 | 272 | 0 |    16 |     16 | 4fe4ce3d9e61c.jpg | running |      0 | 2012-06-22 13:56:18 | 2012-07-23 11:49:14 |          245
     1655 |       1 |      58 | 816 | 0 |    40 |     48 | 4fe4ded96e9be.png | running |      3 | 2012-06-22 15:07:00 | 2012-07-23 11:49:14 |          325
    (5 rows)


only 5 rows with y = 0, which is wrong

Then I went to the log and i see this 

    parameters: $1 = '1636' 
    .....
    2012-07-23 13:49:17 EDT LOG:  duration: 0.022 ms  bind pdo_stmt_000002b8: UPDATE regions    SET x = $1, y = $2, updatedAt = $3 WHERE id = $4
    **2012-07-23 13:49:17 **EDT DETAIL:  parameters: $1 = '5048', $2 = '40', $3 = '2012-07-23 11:49:17', $4 = '1636'
    2012-07-23 13:49:17 EDT LOG:  execute pdo_stmt_000002b8: UPDATE regions SET x = $1, y = $2, updatedAt = $3 WHERE id = $4
    2012-07-23 13:49:17 EDT DETAIL:  parameters: $1 = '5048', $2 = '40', $3 = '2012-07-23 11:49:17', $4 = '1636'****
    2012-07-23 13:49:17 EDT LOG:  duration: 0.123 ms
    2012-07-23 13:49:17 EDT LOG:  duration: 0.030 ms  statement: DEALLOCATE    pdo_stmt_000002b8
    2012-07-23 13:49:17 EDT LOG:  duration: 3.578 ms  statement: COMMIT


Any idea whats goin on here