How to set up entity (doctrine) for database view in Symfony 2

The accepted answer is correct, but I’d like to offer some additional suggestions that you might want to consider:

Mark your entity as read-only.

Make the constructor private so that only Doctrine can create instances.

/**
 * @ORM\Entity(readOnly=true)
 * @ORM\Table(name="your_view_table")
 */
class YourEntity {
    private function __construct() {}
}

Leave a Comment