I am using Symfony2 and Doctrine

I have a doctrine entity which is serialized/unserialized to a session and used in multiple screens. This entity has a number of one to many associations.

The doctrine entity has the following one to many, for example:

class Article {

...

    /**
     * @ORM\OneToMany(targetEntity="image", mappedBy="article", cascade=  {"merge","detach","persist"})
     */
    protected $images;

    public function __construct()
    {
        $this->images = new ArrayCollection();
    }

    .....
}

The article entity is saved and retrieved as follows:

    public function saveArticle($article)
    {
        $articleSerialized = serialize($article);
        $this->session->set('currentArticle',$articleSerialized);
    }

    public function getArticle()
    {
        $articleSerialized = $this->session->get('currentArticle');
        $article = unserialize($articleSerialized);
        $article = $this->em->merge($article);

        return $article;
    }

I am able to save and load the entity to and from the session any number of times, and then merge it back to the entity manager and save. This is only if it is a new entity.

However, once I load an entity from the db and then save it to session, I get problems.

I know, from other posts, that after you unserialise a saved entity, you have to run $em->merge($entity);

I am able to merge the entity, add a new sub-entity (one to many) and then save:

$article = $this->getArticle(); //Declared above, gets article from session

$image = new Image();
$image->setFilename('image.jpeg');
$article->addImage($image);

$this->saveArticle($article); //Declared above, returns the article to session

However, after the first merge and image add, I can't add any more sub-entities. If i try to add a second image, It returns the following error:

Edit
Report