DDC-1246: $em-find or $em->getRepository('Entities\Product')->findBy not working #1568

Closed
opened 2026-01-22 13:18:25 +01:00 by admin · 8 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 3, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user jijioc:

CREATE TABLE Product (
    id INT AUTO_INCREMENT NOT NULL,
    shipping_id INT DEFAULT NULL,
    PRIMARY KEY(id)
) ENGINE = InnoDB;
CREATE TABLE Shipping (
    id INT AUTO_INCREMENT NOT NULL,
    PRIMARY KEY(id)
) ENGINE = InnoDB;
ALTER TABLE Product ADD FOREIGN KEY (shipping_id) REFERENCES Shipping(id);

insert into shipping and product

<?php
/*** @Entity **/
class Product
{
    // ...

    /****
     * @OneToOne(targetEntity="Shipping")
     * @JoinColumn(name="shipping_id", referencedColumnName="id")
     */
    private $shipping;

    // ...
}

/*** @Entity **/
class Shipping
{
    // ...
}
$product = $em->find('Entities\Product', 1); 

==>prints

SELECT t0.id AS id1, t0.shipping*id AS shipping*id2 FROM product t0 WHERE t0.id = ?
array(1) { [0]=> int(1) } array(1) { [0]=> int(1) } 

and the execution get stuck here.

  1. -useless
$shipping = $em->find('Entities\Shipping', 1);
$product = $em->find('Entities\Product', 1);

If the shipping is added manually to the persistent context it seems it's working fine...

    • workaround
$dql = "SELECT p, s FROM Entities\Product p JOIN p.shipping s WHERE p.id=1";
$query = $em->createQuery($dql);
$product = $query->getResult();
Originally created by @doctrinebot on GitHub (Jul 3, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user jijioc: ``` CREATE TABLE Product ( id INT AUTO_INCREMENT NOT NULL, shipping_id INT DEFAULT NULL, PRIMARY KEY(id) ) ENGINE = InnoDB; CREATE TABLE Shipping ( id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id) ) ENGINE = InnoDB; ALTER TABLE Product ADD FOREIGN KEY (shipping_id) REFERENCES Shipping(id); ``` insert into shipping and product ``` <?php /*** @Entity **/ class Product { // ... /**** * @OneToOne(targetEntity="Shipping") * @JoinColumn(name="shipping_id", referencedColumnName="id") */ private $shipping; // ... } /*** @Entity **/ class Shipping { // ... } ``` 1) ``` $product = $em->find('Entities\Product', 1); ``` ==>prints ``` SELECT t0.id AS id1, t0.shipping*id AS shipping*id2 FROM product t0 WHERE t0.id = ? array(1) { [0]=> int(1) } array(1) { [0]=> int(1) } ``` # and the execution get stuck here. 2) -useless ``` $shipping = $em->find('Entities\Shipping', 1); $product = $em->find('Entities\Product', 1); ``` If the shipping is added manually to the persistent context it seems it's working fine... 3) - workaround ``` $dql = "SELECT p, s FROM Entities\Product p JOIN p.shipping s WHERE p.id=1"; $query = $em->createQuery($dql); $product = $query->getResult(); ```
admin added the Bug label 2026-01-22 13:18:25 +01:00
admin closed this issue 2026-01-22 13:18:26 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jul 3, 2011):

Comment created by @beberlei:

Formatting

@doctrinebot commented on GitHub (Jul 3, 2011): Comment created by @beberlei: Formatting
Author
Owner

@doctrinebot commented on GitHub (Jul 3, 2011):

Comment created by @beberlei:

I dont understand what the bug should be here. It looks completly correct to me.

In your case 1, cant you just access Product::$shipping?

@doctrinebot commented on GitHub (Jul 3, 2011): Comment created by @beberlei: I dont understand what the bug should be here. It looks completly correct to me. In your case 1, cant you just access Product::$shipping?
Author
Owner

@doctrinebot commented on GitHub (Jul 3, 2011):

Comment created by jijioc:

the bug consists in the fact that when using,

$product = $em->find('Entities\Product', 1);

the execution of the index.php script stops.

@doctrinebot commented on GitHub (Jul 3, 2011): Comment created by jijioc: the bug consists in the fact that when using, $product = $em->find('Entities\Product', 1); the execution of the index.php script stops.
Author
Owner

@doctrinebot commented on GitHub (Jul 3, 2011):

Comment created by @beberlei:

Can you show the error message that is generated? I cant really reproduce this issue with this little information.

@doctrinebot commented on GitHub (Jul 3, 2011): Comment created by @beberlei: Can you show the error message that is generated? I cant really reproduce this issue with this little information.
Author
Owner

@doctrinebot commented on GitHub (Jul 3, 2011):

Comment created by jijioc:

I'm using the EchoSQLLogger so the only thing that is logged is

SELECT t0.id AS id1, t0.shipping_id AS shipping_id2 FROM product t0 WHERE t0.id = ?
array(1) { [0]=> int(1) } array(1) { [0]=> int(1) }

no explicit error

@doctrinebot commented on GitHub (Jul 3, 2011): Comment created by jijioc: I'm using the EchoSQLLogger so the only thing that is logged is SELECT t0.id AS id1, t0.shipping_id AS shipping_id2 FROM product t0 WHERE t0.id = ? array(1) { [0]=> int(1) } array(1) { [0]=> int(1) } no explicit error
Author
Owner

@doctrinebot commented on GitHub (Jul 3, 2011):

Comment created by @beberlei:

Have you turned display errors off maybe? Or does your framework (if used) eat an exception that is thrown?

Can you install xdebug pecl extension and do an xdebug_start_trace() before that $em->find() call? That would help pinning the issue down.

@doctrinebot commented on GitHub (Jul 3, 2011): Comment created by @beberlei: Have you turned display errors off maybe? Or does your framework (if used) eat an exception that is thrown? Can you install xdebug pecl extension and do an xdebug_start_trace() before that $em->find() call? That would help pinning the issue down.
Author
Owner

@doctrinebot commented on GitHub (Jul 3, 2011):

Comment created by jijioc:

The problem was:
[03-Jul-2011 12:30:20] PHP Fatal error: require() [function.require]: Failed opening required
'D:\Program Files\Zend\Apache2\htdocs\hr/Proxies\EntitiesShippingProxy.php'
(include_path='.;D:\Program Files\Zend\ZendServer\share\ZendFramework\library')
in D:\Program Files\Zend\Apache2\htdocs\hr\Doctrine\ORM\Proxy\ProxyFactory.php on line 85

so after I created the directory Proxies everyting is running fine

Thanks. you can close the bug... sorry

@doctrinebot commented on GitHub (Jul 3, 2011): Comment created by jijioc: The problem was: [03-Jul-2011 12:30:20] PHP Fatal error: require() [<a href='function.require'>function.require</a>]: Failed opening required 'D:\Program Files\Zend\Apache2\htdocs\hr/Proxies\EntitiesShippingProxy.php' (include_path='.;D:\Program Files\Zend\ZendServer\share\ZendFramework\library') in D:\Program Files\Zend\Apache2\htdocs\hr\Doctrine\ORM\Proxy\ProxyFactory.php on line 85 so after I created the directory Proxies everyting is running fine Thanks. you can close the bug... sorry
Author
Owner

@doctrinebot commented on GitHub (Jul 3, 2011):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Jul 3, 2011): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1568