Php spl_object_hash()期望参数1为object,给定为null

Php spl_object_hash()期望参数1为object,给定为null,php,doctrine-orm,Php,Doctrine Orm,在一个项目中,我使用原则2,其中我有一对多的关系,如: 客户=>订单 我的问题看起来与问题类似,只是我在尝试使用arraycollection()检索实体时已出现错误: Customer.php的内容如下所示: <?php namespace Application\Entity; use Doctrine\ORM\Mapping as ORM; /** * Customer * * @ORM\Table(name="customer", uniqueConstraints={

在一个项目中,我使用原则2,其中我有一对多的关系,如:

客户=>订单

我的问题看起来与问题类似,只是我在尝试使用arraycollection()检索实体时已出现错误:

Customer.php的内容如下所示:

<?php

namespace Application\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Customer
 *
 * @ORM\Table(name="customer", uniqueConstraints={@ORM\UniqueConstraint(name="foo", columns={"foo"})})
 * @ORM\Entity
 */
class Customer
{

    public function __construct() {
        $this->orders = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * @var \Application\Entity\User
     *
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="NONE")
     * @ORM\OneToOne(targetEntity="Application\Entity\User")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id", referencedColumnName="id")
     * })
     */
    private $id;


    /**
     * 
     * @var \Doctrine\Common\Collections\ArrayCollection
     * 
     * @ORM\OneToMany(targetEntity="Order", mappedBy="customer", fetch="EAGER")
     * 
     */
    private $orders;


    /**
     * @return \Doctrine\Common\Collections\ArrayCollection a list of orders related to the customer
     */
    public function getOrders() {
        return $this->orders;
    }

    /**
     * Set id
     *
     * @param \Application\Entity\User $id
     * @return Customer
     */
    public function setId(\Application\Entity\User $id) {
        $this->id = $id;

        return $this;
    }

    /**
     * Get id
     *
     * @return \Application\Entity\User 
     */
    public function getId() {
        return $this->id;
    }

}
Update2:由于客户内部的id是用户对象,我也尝试了以下操作,但没有成功:

$entityManager->getRepository('\Application\Entity\Customer')->find($user);

我已经试过第页的答案了,但是没有用!我需要做什么才能使其正常工作?

我想在其中添加一对多关系的实体类有一个主键,该主键作为一对一关系映射到导致问题的另一个实体。因此,为了解决这个问题,我确实删除了一对一关系,并更新了代码,使其在没有一对一映射的情况下工作。

您正在执行哪个方法触发此错误?你只发布了你的实体代码。谢谢布拉姆,我更新了代码。我还发现了导致问题的原因。当主键也是另一个表的外键时,原则2似乎不适用于一对多。但我很好奇是否还有其他解决方案,因为我不能删除这段代码。否则,我的应用程序的其他部分可能无法工作
$entityManager->getRepository('\Application\Entity\Customer')->find($user->getId());//debugger shows $user->id = 7 so that isn't causing the problem
$entityManager->getRepository('\Application\Entity\Customer')->find($user);