DDC-19: Can't unserialize serialized entity which has a proxy as a single valued relationship as a value #25

Open
opened 2026-01-22 12:24:39 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 21, 2009).

Jira issue originally created by user ablock:

namespace Test;
/****
 * @Entity
 */
class Book {
    /**** 
     * @Id @Column(type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;

    /****
         * @OneToOne(targetEntity="Author",cascade={"persist"})
         * @JoinColumn(name="author_id", referencedColumnName="id")
         */
    private $author;

    public function setAuthor(Author $a) {
        $this->author = $a;
    }   

    public function getAuthor() {
        return $this->author;
    }
}

/****
 * @Entity
 */
class Author {
    /****
     * @Id @Column(type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;

    /****
     * @Column(type="string")
     */
    private $name;

    public function setName($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}
include 'entities.php';
include 'config.php';

$query = $em->createQuery('select b from Test\Book b where b.id = 1');
$book = $query->getSingleResult();
$book->getAuthor()->getName(); // If I don't do this, the object is not "loaded" and I can't serialize it.
file*put*contents('out',serialize($book));
include 'entities.php';
include 'config.php';
$b = unserialize(file*get*contents('out'));

This generates the error:

PHP Fatal error:  require(): Failed opening required '/home/ablock/doctrine/lib/Doctrine/Generated/Proxies/Test_AuthorAProxy.php'
Originally created by @doctrinebot on GitHub (Sep 21, 2009). Jira issue originally created by user ablock: ``` namespace Test; /**** * @Entity */ class Book { /**** * @Id @Column(type="integer") * @GeneratedValue(strategy="AUTO") */ private $id; /**** * @OneToOne(targetEntity="Author",cascade={"persist"}) * @JoinColumn(name="author_id", referencedColumnName="id") */ private $author; public function setAuthor(Author $a) { $this->author = $a; } public function getAuthor() { return $this->author; } } /**** * @Entity */ class Author { /**** * @Id @Column(type="integer") * @GeneratedValue(strategy="AUTO") */ private $id; /**** * @Column(type="string") */ private $name; public function setName($name) { $this->name = $name; } public function getName() { return $this->name; } } ``` ``` include 'entities.php'; include 'config.php'; $query = $em->createQuery('select b from Test\Book b where b.id = 1'); $book = $query->getSingleResult(); $book->getAuthor()->getName(); // If I don't do this, the object is not "loaded" and I can't serialize it. file*put*contents('out',serialize($book)); ``` ``` include 'entities.php'; include 'config.php'; $b = unserialize(file*get*contents('out')); ``` This generates the error: ``` PHP Fatal error: require(): Failed opening required '/home/ablock/doctrine/lib/Doctrine/Generated/Proxies/Test_AuthorAProxy.php' ```
admin added the Bug label 2026-01-22 12:24:39 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#25