Error: Expected Doctrine\ORM\Query\Lexer::T_IDENTIFIER, got '*'

Error: Expected Doctrine\ORM\Query\Lexer::T_IDENTIFIER, got '*'

我正在尝试从 symfony 中的嵌套树结构生成一个 JSON 文件。 它用于 jquery-fancytree。因此,我正在处理 sql 查询。

但是我的 RolesRepository 给出了
错误:应为 Doctrine\ORM\Query\Lexer::T_IDENTIFIER,得到“*”

SQL 手动查询有效

class RolesRepository extends \Doctrine\ORM\EntityRepository
{


    public function getNestedToJSON()
    {
        $em = $this->getEntityManager();
        $query = $em->createQuery(
            'SELECT n.* , round((n.Rght-n.Lft-1)/2,0) AS offspring,
              count(*)-1 + (n.Lft>1) AS level,
              ((min(p.Rght)-n.Rght-( n.Lft >1 ))/2) > 0 AS lower,
              (((n.Lft-max(p.Lft)>1))) AS upper 
              FROM md_roles n, md_roles p 
              WHERE n.Lft BETWEEN p.Lft AND p.Rght 
              AND (p.id != n.id OR n.Lft = 1) 
              GROUP BY n.id 
              ORDER BY n.Lft')
            ->getResult();


        return $query;


    }
}

实体:

/**
 * UserRoles
 *
 * @ORM\Table(name="md_roles",
 *     options={"collate":"utf8_general_ci", "charset":"utf8", "engine":"InnoDB"})
 * @ORM\Entity(repositoryClass="AppBundle\Repository\RolesRepository")
 */



class Roles
{
    /**
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Id
     */
    protected $ID;

    /**
     * @ORM\Column(name="Lft", columnDefinition="INT(11) NOT NULL")
     */
    protected $Lft;

    /**
     * @ORM\Column(name="Rght", columnDefinition="INT(11) NOT NULL")
     */
    protected $Rght;

    /**
     * @ORM\Column(name="Title", columnDefinition="char(128) NOT NULL")
     */
    protected $Title;

    /**
     * @ORM\Column(name="Description", columnDefinition="text NOT NULL")
     */
    protected $Description;




    /**
     * @return integer
     */
    public function getID()
    {
        return $this->ID;
    }

    /**
     * @return Roles
     */
    public function setID($ID)
    {
        $this->ID = $ID;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getLft()
    {
        return $this->Lft;
    }

    /**
     * @param mixed $Lft
     * @return Roles
     */
    public function setLft($Lft)
    {
        $this->Lft = $Lft;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getRght()
    {
        return $this->Rght;
    }

    /**
     * @param mixed $Rght
     * @return Roles
     */
    public function setRght($Rght)
    {
        $this->Rght = $Rght;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getTitle()
    {
        return $this->Title;
    }

    /**
     * @param mixed $Title
     * @return Roles
     */
    public function setTitle($Title)
    {
        $this->Title = $Title;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getDescription()
    {
        return $this->Description;
    }

    /**
     * @param mixed $Description
     * @return Roles
     */
    public function setDescription($Description)
    {
        $this->Description = $Description;
        return $this;
    }



}

有人知道为什么吗?

您尝试执行 SQL 但此函数需要一个 DQL 字符串。而是将 $em->createNativeQuery() 用于普通 SQL 语句或将您的 SQL 转换为等效的 DQL 表达式。