Entity has to be managed or scheduled for removal for single computation in Symfony/twig
<p>When I try to <code>delete or clear</code> rates of courier company it throws out following error. I think I don't have good debugging skills. Can anybody help me, what is the reason behind this? Here is controller, view and modal. </p>

<pre><code> Entity has to be managed or scheduled for removal for single computation Sokosimu\PostalDeliveryBundle\Entity\PostalCharge@0000000059f7113c00000000372b1d9d
</code></pre>

<p><strong>Controller</strong></p>

<pre><code> public function clearRatesAction(DeliveryCompany $deliveryCompany){

    $em = $this-&gt;get('doctrine')-&gt;getManager();
    $postalcharge = new PostalCharge();
    $em-&gt;getConnection()-&gt;beginTransaction();
    try {

        $rate = $postalcharge -&gt;setDeliveryCompany($deliveryCompany);
        $em-&gt;persist($rate);
        $em-&gt;remove($rate);
        $em-&gt;flush($rate);
        $em-&gt;getConnection()-&gt;commit();
    }  catch(Exception $e){
        $em-&gt;getConnection()-&gt;rollback();
        throw $e;
    }
    return $this-&gt;redirect($this-&gt;generateUrl('sokosimu_postal_delivery_list_company'));
}
}
</code></pre>

<p><strong>Twig (Views)</strong></p>

<pre><code>&lt;tbody&gt;
   {% for deliveryCompany in deliveryCompanyList %}
     &lt;tr&gt;
    &lt;td&gt;&lt;a href="{{ path('sokosimu_postal_delivery_company_detail',{'deliveryCompany':deliveryCompany.getid()}) }}"&gt;{{ deliveryCompany.getName() }}&lt;/td&gt;
&lt;td&gt;{{ deliveryCompany.getAddress() }}&lt;/td&gt;
 &lt;td&gt;&lt;a href="{{ path('sokosimu_postal_delivery_company_edit',{'deliveryCompany':deliveryCompany.getId()}) }}"&gt;Edit&lt;/a&gt;
 &lt;a href="{{ path('sokosimu_postal_delivery_clear_rates',{'deliveryCompany':deliveryCompany.getId()}) }}"&gt;ClearRates&lt;/a&gt;
                                &lt;/td&gt;
                            &lt;/tr&gt;
 {% endfor %}
 &lt;/tbody&gt;
</code></pre>

<p><strong>Postal charge entity</strong></p>

<pre><code>     &lt;?php
    // src/Sokosimu/PostalDeliveryBundle/Entity/PostalCharge.php

    namespace Sokosimu\PostalDeliveryBundle\Entity;

    use Doctrine\ORM\Mapping as ORM;

    /**  *                 @ORM\Entity(repositoryClass="Sokosimu\PostalDeliveryBundle\Entity\Repository\PostalChargeRepository")
  * @ORM\Table(name="postal_charge")
  * @ORM\HasLifecycleCallbacks()
  */

class PostalCharge
{

/**
 * @ORM\Id
 * @ORM\Column(name="id",type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(name="record_type",type="string", length=225)
 */
protected $recordType;

/**
 * @ORM\Column(name="active_from",type="datetime",  nullable=True)
 */
protected $activeFrom;

/**
 * @ORM\Column(name="active_to",type="datetime",  nullable=True)
 */
protected $activeTo;

/**
 * @ORM\Column(name="active_record",type="string", length=225, nullable=True)
 */
protected $activeRecord;

/**
 * @ORM\Column(name="origin_country",type="string", length=225, nullable=True)
 */
protected $originCountry;

/**
 * @ORM\Column(name="weight_from",type="integer")
 */
protected $weightFrom;

/**
 * @ORM\Column(name="weight_to",type="integer")
 */
protected $weightTo;

/**
 * @ORM\Column(name="from_region",type="string", length=225, nullable=True)
 */
protected $fromRegion;

/**
 * @ORM\Column(name="to_region",type="string", length=225, nullable=True)
 */
protected $toRegion;

/**
 * @ORM\Column(name="priority",type="string", length=225, nullable=True)
 */
protected $priority;

/**
 * @ORM\Column(name="economy",type="string", length=225, nullable=True)
 */
protected $economy;

/**
 * @ORM\Column(name="increment_price",type="string", length=225, nullable=True)
 */
protected $incrementPrice;

/**
 * @ORM\Column(name="tax",type="string", length=225, nullable=True)
 */
protected $tax;

/**
 * @ORM\Column(name="insurance",type="string", length=225, nullable=True)
 */
protected $insurance;

/**
 * @ORM\Column(name="increment_unit",type="string", length=225, nullable=True)
 */
protected $incrementUnit;


/**
 * @ORM\Column(name="currency_code",type="string", length=225, nullable=True)
 */
protected $currencyCode;

/**
 * @ORM\Column(name="country_code",type="string", length=225, nullable=True)
 */
protected $countryCode;

/**
 * @ORM\ManyToOne(targetEntity="DeliveryCompany")
 * @ORM\JoinColumn(name="delivery_company_id",referencedColumnName="id",nullable=True)
 */
protected $deliveryCompany;


/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this-&gt;id;
}

/**
 * Set recordType
 *
 * @param string $recordType
 * @return PostalCharge
 */
public function setRecordType($recordType)
{
    $this-&gt;recordType = $recordType;

    return $this;
}

/**
 * Get recordType
 *
 * @return string 
 */
public function getRecordType()
{
    return $this-&gt;recordType;
}

/**
 * Set activeFrom
 *
 * @param \DateTime $activeFrom
 * @return PostalCharge
 */
public function setActiveFrom($activeFrom)
{
    $this-&gt;activeFrom = $activeFrom;

    return $this;
}

/**
 * Get activeFrom
 *
 * @return \DateTime 
 */
public function getActiveFrom()
{
    return $this-&gt;activeFrom;
}

/**
 * Set activeTo
 *
 * @param \DateTime $activeTo
 * @return PostalCharge
 */
public function setActiveTo($activeTo)
{
    $this-&gt;activeTo = $activeTo;

    return $this;
}

/**
 * Get activeTo
 *
 * @return \DateTime 
 */
public function getActiveTo()
{
    return $this-&gt;activeTo;
}

/**
 * Set activeRecord
 *
 * @param string $activeRecord
 * @return PostalCharge
 */
public function setActiveRecord($activeRecord)
{
    $this-&gt;activeRecord = $activeRecord;

    return $this;
}

/**
 * Get activeRecord
 *
 * @return string 
 */
public function getActiveRecord()
{
    return $this-&gt;activeRecord;
}

/**
 * Set originCountry
 *
 * @param string $originCountry
 * @return PostalCharge
 */
public function setOriginCountry($originCountry)
{
    $this-&gt;originCountry = $originCountry;

    return $this;
}

/**
 * Get originCountry
 *
 * @return string 
 */
public function getOriginCountry()
{
    return $this-&gt;originCountry;
}

/**
 * Set weightFrom
 *
 * @param integer $weightFrom
 * @return PostalCharge
 */
public function setWeightFrom($weightFrom)
{
    $this-&gt;weightFrom = $weightFrom;

    return $this;
}

/**
 * Get weightFrom
 *
 * @return integer 
 */
public function getWeightFrom()
{
    return $this-&gt;weightFrom;
}

/**
 * Set weightTo
 *
 * @param integer $weightTo
 * @return PostalCharge
 */
public function setWeightTo($weightTo)
{
    $this-&gt;weightTo = $weightTo;

    return $this;
}

/**
 * Get weightTo
 *
 * @return integer 
 */
public function getWeightTo()
{
    return $this-&gt;weightTo;
}

/**
 * Set fromRegion
 *
 * @param string $fromRegion
 * @return PostalCharge
 */
public function setFromRegion($fromRegion)
{
    $this-&gt;fromRegion = $fromRegion;

    return $this;
}

/**
 * Get fromRegion
 *
 * @return string 
 */
public function getFromRegion()
{
    return $this-&gt;fromRegion;
}

/**
 * Set toRegion
 *
 * @param string $toRegion
 * @return PostalCharge
 */
public function setToRegion($toRegion)
{
    $this-&gt;toRegion = $toRegion;

    return $this;
}

/**
 * Get toRegion
 *
 * @return string 
 */
public function getToRegion()
{
    return $this-&gt;toRegion;
}

/**
 * Set priority
 *
 * @param string $priority
 * @return PostalCharge
 */
public function setPriority($priority)
{
    $this-&gt;priority = $priority;

    return $this;
}

/**
 * Get priority
 *
 * @return string 
 */
public function getPriority()
{
    return $this-&gt;priority;
}

/**
 * Set economy
 *
 * @param string $economy
 * @return PostalCharge
 */
public function setEconomy($economy)
{
    $this-&gt;economy = $economy;

    return $this;
}

/**
 * Get economy
 *
 * @return string 
 */
public function getEconomy()
{
    return $this-&gt;economy;
}

/**
 * Set incrementPrice
 *
 * @param string $incrementPrice
 * @return PostalCharge
 */
public function setIncrementPrice($incrementPrice)
{
    $this-&gt;incrementPrice = $incrementPrice;

    return $this;
}

/**
 * Get incrementPrice
 *
 * @return string 
 */
public function getIncrementPrice()
{
    return $this-&gt;incrementPrice;
}

/**
 * Set tax
 *
 * @param string $tax
 * @return PostalCharge
 */
public function setTax($tax)
{
    $this-&gt;tax = $tax;

    return $this;
}

/**
 * Get tax
 *
 * @return string 
 */
public function getTax()
{
    return $this-&gt;tax;
}

/**
 * Set insurance
 *
 * @param string $insurance
 * @return PostalCharge
 */
public function setInsurance($insurance)
{
    $this-&gt;insurance = $insurance;

    return $this;
}

/**
 * Get insurance
 *
 * @return string 
 */
public function getInsurance()
{
    return $this-&gt;insurance;
}

/**
 * Set incrementUnit
 *
 * @param string $incrementUnit
 * @return PostalCharge
 */
public function setIncrementUnit($incrementUnit)
{
    $this-&gt;incrementUnit = $incrementUnit;

    return $this;
}

/**
 * Get incrementUnit
 *
 * @return string 
 */
public function getIncrementUnit()
{
    return $this-&gt;incrementUnit;
}

/**
 * Set currencyCode
 *
 * @param string $currencyCode
 * @return PostalCharge
 */
public function setCurrencyCode($currencyCode)
{
    $this-&gt;currencyCode = $currencyCode;

    return $this;
}

/**
 * Get currencyCode
 *
 * @return string 
 */
public function getCurrencyCode()
{
    return $this-&gt;currencyCode;
}

/**
 * Set countryCode
 *
 * @param string $countryCode
 * @return PostalCharge
 */
public function setCountryCode($countryCode)
{
    $this-&gt;countryCode = $countryCode;

    return $this;
}

/**
 * Get countryCode
 *
 * @return string 
 */
public function getCountryCode()
{
    return $this-&gt;countryCode;
}

/**
 * Set deliveryCompany
 *
 * @param \Sokosimu\PostalDeliveryBundle\Entity\DeliveryCompany $deliveryCompany
 * @return PostalCharge
 */
public function setDeliveryCompany(\Sokosimu\PostalDeliveryBundle\Entity\DeliveryCompany $deliveryCompany = null)
{
    $this-&gt;deliveryCompany = $deliveryCompany;

    return $this;
}

/**
 * Get deliveryCompany
 *
 * @return \Sokosimu\PostalDeliveryBundle\Entity\DeliveryCompany 
 */
public function getDeliveryCompany()
{
    return $this-&gt;deliveryCompany;
}
}
</code></pre>