我正在为我的应用程序使用 Symfony2,并且正在使用两个实体管理器;一个用于读取,另一个用于写入。
我正在创建这样的实体管理器对象:
$em = $this->getDoctrine()->getEntityManager('write');
$em = $this->getDoctrine()->getEntityManager('read');
最初它工作正常,但现在出现以下错误:
通过关系 '
AppBundle\Entity\ProfileViewer#viewer
' 找到一个新实体,该实体未配置为对实体进行级联持久化操作:shamsi
。显式持久化新实体或在关系上配置级联持久化操作。
这是我的 ProfileViewer 实体:
/**
* AppBundle\Entity\ProfileViewer
*
* @ORM\Table(name="profile_viewer")
* @ORM\Entity
*/
class ProfileViewer
{
/**
* @var bigint $id
*
* @ORM\Column(name="id", type="bigint", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var bigint $userId
*
* @ORM\Column(name="user_id", type="bigint", nullable=false)
*/
private $userId;
/**
* @var datetime $viewedAt
*
* @ORM\Column(name="viewed_at", type="datetime", nullable=true)
*/
private $viewedAt;
/**
* @ORM\ManyToOne(targetEntity="user", inversedBy="viewers")
* @ORM\JoinColumn(name="viewer_id", referencedColumnName="id")
*/
private $viewer;
public function __construct()
{
$this->viewedAt = new \DateTime();
}
/**
* Get id
*
* @return bigint
*/
public function getId()
{
return $this->id;
}
/**
* Set userId
*
* @param bigint $userId
*/
public function setUserId($userId)
{
$this->userId = $userId;
}
/**
* Get UserId
*
* @return bigint
*/
public function getUserId()
{
return $this->userId;
}
/**
* Set viewedAt
*
* @param datetime $viewedAt
*/
public function setViewedAt($viewedAt)
{
$this->viewedAt = $viewedAt;
}
/**
* Get viewedAt
*
* @return datetime
*/
public function getViewedAt()
{
return $this->viewedAt;
}
/**
* Set viewer
*
* @param AppBundle\Entity\User $viewer
*/
public function setViewer(AppBundle\Entity\User $viewer)
{
$this->viewer = $viewer;
}
/**
* Get viewer
*
* @return AppBundle\Entity\User
*/
public function getViewer()
{
return $this->viewer;
}
}
当我创建了两个实体管理器时会出现此错误。