Organizational Research By

Surprising Reserch Topic

a new entity was found through the relationship doctrine

a new entity was found through the relationship doctrine  using -'orm,zend-framework,doctrine,entity'

The application has thrown an exception!


A new entity was found through the relationship 'Core\Model\Filter#category' that was not configured to cascade persist operations for entity: Core\Model\Category@00000000314fc99200005639c0395a5e. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist  this association in the mapping for example @ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement 'Core\Model\Category#__toString()' to get a clue.

This function cause an exception.
Some comits in code.
It is ZendFramework 2.

protected function handleCategory( $data, \Core\Model\Project $project )
    $filter = $this->sl()->get( "Core\Filter\JSON\Category" );
    $filter->setData( $data );
    if( !$filter->isValid() ){
        $id = @$data[ 'id' ];
        $report = array(
            'id' => $id,
            'messages' => $filter->getMessages()
        return $report;

    $filteredData = $filter->getValues();
    $repo = $this->em()->getRepository( "Core\Model\Category" );
    $category = $repo->findOneBy(
            'id' => $filteredData[ 'id' ],
            'project' => $project->getId()

    $b = false;
    if( !$category ){
        $b = true;
        $category = new \Core\Model\Category;
        $category->setProject( $project )
                ->setCreatedAt( new \DateTime() );
    $category->setUpdatedAt( new \DateTime() );

    /* Hydrate Category  */
    $hydrator = $this->sl()->get( "Core\Hydrator\JSON\Category" );
    $hydrator->hydrate( $filteredData, $category );

    /* Persist Category */

        /* Return Filter Data */
        $filterData = $hydrator->get();

        /* Hydrate Filter */
        $filterHydrator = $this->sl()->get( 'Core\Hydrator\JSON\Filter' );
        //$filtersObj = array();
        foreach($filterData as $i => $fdata)
            $filterObj = new \Core\Model\Filter;
            $filterHydrator->hydrate($fdata, $filterObj);

            /*Breaks after any flush after second persist*/

    return true;

I tried to solve this problem by:

MERGE, but get another exception, A managed dirty+entity [...]
cascade={"persist"}, but nothing happend.
rewrite code in that what you see, i made all persists in one function one by one with one EntityManager.(If i missing something please tell me)

Never work before with ZendFramework. I love Symfony with app/console manager, all entities with tables creates authomatically.

asked Oct 23, 2015 by manju bhargava
0 votes

Related Hot Questions

1 Answer

0 votes
answered Oct 23, 2015 by thiru