[DDC-1333] doctrine-mapping.xsd allows only one <id> element Created: 16/Aug/11  Updated: 21/Aug/11  Resolved: 21/Aug/11

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: Mapping Drivers
Affects Version/s: 2.1
Fix Version/s: 2.1.1

Type: Bug Priority: Minor
Reporter: Andrew McConnell Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

The metadata XSD at http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd defines the <id> element on line 66 as <xs:element name="id" type="orm:id" minOccurs="0" maxOccurs="1" />. This allows for no more than one <id> element though the documentation at http://www.doctrine-project.org/docs/orm/2.1/en/reference/xml-mapping.html#defining-identity-and-generator-strategies states that more than one <id> element is allowed.



 Comments   
Comment by Benjamin Eberlei [ 21/Aug/11 ]

Fixed





[DDC-1300] Can't fetch entities from IdentityMap when using a foreign keys as identifiers Created: 27/Jul/11  Updated: 06/Aug/11  Resolved: 06/Aug/11

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.1
Fix Version/s: 2.1.1

Type: Bug Priority: Critical
Reporter: Van Hauwaert Bert Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

Given the follow SQL structure:

CREATE TABLE `foo` (
  `fooID` int(11) NOT NULL AUTO_INCREMENT,
  `fooReference` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`fooID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='module=bug';

CREATE TABLE `fooLocale` (
  `fooID` int(11) NOT NULL,
  `locale` varchar(5) NOT NULL DEFAULT '',
  `title` varchar(150) DEFAULT NULL,
  PRIMARY KEY (`fooID`,`locale`),
  KEY `fk_foo2` (`fooID`),
  CONSTRAINT `fk_table1_foo2` FOREIGN KEY (`fooID`) REFERENCES `foo` (`fooID`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module=bug';

INSERT INTO `foo` (`fooID`, `fooReference`)
VALUES
	(1, 'foo1');

INSERT INTO `fooLocale` (`fooID`, `locale`, `title`)
VALUES
	(1, 'en_GB', 'Foo title test');

and the following models:

use Doctrine\ORM\Mapping as ORM;

/**
 * Model for foo
 *
 * @category Application
 * @package Bug
 * @subpackage Model
 * @ORM\Table(name="foo")
 * @ORM\Entity
 */
class Bug_Model_Foo
{
	/**
	 * @var integer fooID
	 * @ORM\Column(name="fooID", type="integer", nullable=false)
	 * @ORM\GeneratedValue(strategy="IDENTITY")
	 * @ORM\Id
	 */
	protected $_fooID = null;

	/**
	 * @var string fooReference
	 * @ORM\Column(name="fooReference", type="string", nullable=true, length=45)
	 */
	protected $_fooReference = null;

	/**
	 * @ORM\OneToMany(targetEntity="Bug_Model_FooLocale", mappedBy="_foo",
	 * cascade={"persist"})
	 */
	protected $_fooLocaleRefFoo = null;

	/**
	 * Constructor
	 *
	 * @param array|Zend_Config|null $options
	 * @return Bug_Model_Foo
	 */
	public function __construct($options = null)
	{
		$this->_fooLocaleRefFoo = new \Doctrine\Common\Collections\ArrayCollection();
	}

}
use Doctrine\ORM\Mapping as ORM;

/**
 * Model for fooLocale
 *
 * @category Application
 * @package Bug
 * @subpackage Model
 * @ORM\Table(name="fooLocale")
 * @ORM\Entity
 */
class Bug_Model_FooLocale
{
	/**
	 * @ORM\ManyToOne(targetEntity="Bug_Model_Foo")
	 * @ORM\JoinColumn(name="fooID", referencedColumnName="fooID")
	 * @ORM\Id
	 */
	protected $_foo = null;

	/**
	 * @var string locale
	 * @ORM\Column(name="locale", type="string", nullable=false, length=5)
	 * @ORM\Id
	 */
	protected $_locale = null;

	/**
	 * @var string title
	 * @ORM\Column(name="title", type="string", nullable=true, length=150)
	 */
	protected $_title = null;

}

Execute the following DQL 2 times:

$query = $entityManager->createQuery('
			SELECT 
				f, fl 
			FROM 
				Bug_Model_Foo f 
			JOIN 
				f._fooLocaleRefFoo fl');
		return $query->getResult();

The first time, you won't have any issues.
The second time, when the data will be fetched from the identityMap, you won't find it because there is something wrong with the identities and you will get the following warning

( ! ) Notice: Undefined index: _foo in /var/www/vhost/core/htdocs/externals/Doctrine/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php on line 217
Call Stack
#	Time	Memory	Function	Location
1	0.0002	337752	{main}( )	../index.php:0
2	0.0848	7268724	Zend_Application->run( )	../index.php:26
3	0.0848	7268724	Zend_Application_Bootstrap_Bootstrap->run( )	../Application.php:366
4	0.0850	7268796	Zend_Controller_Front->dispatch( )	../Bootstrap.php:97
5	0.0908	7900416	Zend_Controller_Dispatcher_Standard->dispatch( )	../Front.php:954
6	0.0967	8209564	Zend_Controller_Action->dispatch( )	../Standard.php:295
7	0.0967	8213912	Bug_IndexController->indexAction( )	../Action.php:513
8	0.1936	11391900	Bug_Service_Bug->getFooLocaleList( )	../IndexController.php:35
9	0.1936	11394088	Doctrine\ORM\AbstractQuery->getResult( )	../Bug.php:41
10	0.1936	11394296	Doctrine\ORM\AbstractQuery->execute( )	../AbstractQuery.php:392
11	0.1945	11397960	Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll( )	../AbstractQuery.php:594
12	0.1946	11398656	Doctrine\ORM\Internal\Hydration\ObjectHydrator->_hydrateAll( )	../AbstractHydrator.php:99
13	0.1946	11399876	Doctrine\ORM\Internal\Hydration\ObjectHydrator->_hydrateRow( )	../ObjectHydrator.php:140
14	0.1949	11405584	Doctrine\ORM\Internal\Hydration\ObjectHydrator->_getEntityFromIdentityMap( )	../ObjectHydrator.php:326

With the invalid key, it is not possible to get the entity from the identityMap.



 Comments   
Comment by Benjamin Eberlei [ 06/Aug/11 ]

I could reproduce this, working on a fix.

Comment by Benjamin Eberlei [ 06/Aug/11 ]

Fixed





Generated at Tue Sep 01 14:14:00 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.