<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Wed May 22 16:38:27 UTC 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://www.doctrine-project.org/jira/si/jira.issueviews:issue-xml/DDC-1928/DDC-1928.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://www.doctrine-project.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.7</version>
        <build-number>850</build-number>
        <build-date>21-02-2013</build-date>
    </build-info>

<item>
            <title>[DDC-1928] one-to-one relations mapping</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-1928</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;hello, im new here i dont know if this is the correct place, but try finding help on the web whitout success. so here is my issue.&lt;/p&gt;

&lt;p&gt;im trying to map a one to one relation on 2 entities using the id field on both entities.&lt;/p&gt;

&lt;p&gt;for example:&lt;/p&gt;

&lt;p&gt;i have a customer entity and a cart entity, both entities have only an id field. and there is a FK from cart id to customer id so i make the mappings as follow:&lt;/p&gt;

&lt;p&gt;first the customer:&lt;/p&gt;

&lt;p&gt;Acme\DemoBundle\Entity\Customer:&lt;br/&gt;
    type: entity&lt;br/&gt;
    table: null    &lt;br/&gt;
    oneToOne:&lt;br/&gt;
      cart:&lt;br/&gt;
        targetEntity: Cart&lt;br/&gt;
        mappedBy: customer&lt;br/&gt;
    fields:&lt;br/&gt;
        id:&lt;br/&gt;
            type: integer&lt;br/&gt;
            id: true&lt;br/&gt;
            generator:&lt;br/&gt;
                strategy: AUTO&lt;br/&gt;
    lifecycleCallbacks: {  }&lt;/p&gt;

&lt;p&gt;now the cart:&lt;/p&gt;

&lt;p&gt;Acme\DemoBundle\Entity\Cart:&lt;br/&gt;
    type: entity&lt;br/&gt;
    table: null&lt;br/&gt;
    oneToOne:&lt;br/&gt;
      customer:&lt;br/&gt;
        targetEntity: Customer&lt;br/&gt;
        inversedBy: cart&lt;br/&gt;
        joinColumn:&lt;br/&gt;
          name: id&lt;br/&gt;
          referencedColumnName: id&lt;br/&gt;
    fields:&lt;br/&gt;
        id:&lt;br/&gt;
            type: integer&lt;br/&gt;
            id: true&lt;/p&gt;

&lt;p&gt;    lifecycleCallbacks: {  }&lt;/p&gt;

&lt;p&gt;the entities get generated ok, but im not able to insert in the cart entity:&lt;/p&gt;

&lt;p&gt;im getting the followin exception:&lt;/p&gt;

&lt;p&gt;Entity of type Acme\DemoBundle\Entity\Cart is missing an assigned ID for field &apos;id&apos;. The identifier generation strategy for this entity requires the ID field to be populated before EntityManager#persist() is called. If you want automatically generated identifiers instead you need to adjust the metadata mapping accordingly. &lt;/p&gt;

&lt;p&gt;when i made the insert a try this two ways:&lt;/p&gt;

&lt;p&gt;        $cart = new \Acme\DemoBundle\Entity\Cart();&lt;br/&gt;
        $cart-&amp;gt;setId($cart-&amp;gt;getId());&lt;br/&gt;
        $em-&amp;gt;persist($cart);        &lt;br/&gt;
        $em-&amp;gt;flush();&lt;/p&gt;

&lt;p&gt;or this one&lt;/p&gt;

&lt;p&gt;        $cart = new \Acme\DemoBundle\Entity\Cart();&lt;br/&gt;
        $cart-&amp;gt;setCustomer($customer);&lt;br/&gt;
        $em-&amp;gt;persist($cart);        &lt;br/&gt;
        $em-&amp;gt;flush();&lt;br/&gt;
in both cases i get the same exception&lt;/p&gt;

&lt;p&gt;this is the symfony&apos;s log where the insert is generated by doctrine to insert the cart record&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;2012-07-16 20:59:06&amp;#93;&lt;/span&gt; doctrine.DEBUG: SET NAMES UTF8 ([]) [] []&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;2012-07-16 20:59:06&amp;#93;&lt;/span&gt; doctrine.DEBUG: INSERT INTO Customer (id) VALUES (null) ([]) [] []&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;2012-07-16 20:59:06&amp;#93;&lt;/span&gt; event.DEBUG: Notified event &quot;kernel.exception&quot; to listener &quot;Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException&quot;. [] []&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;2012-07-16 20:59:06&amp;#93;&lt;/span&gt; event.DEBUG: Notified event &quot;kernel.exception&quot; to listener &quot;Symfony\Component\HttpKernel\EventListener\ExceptionListener::onKernelException&quot;. [] []&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;2012-07-16 20:59:06&amp;#93;&lt;/span&gt; request.CRITICAL: Doctrine\ORM\ORMException: Entity of type Acme\DemoBundle\Entity\Cart is missing an assigned ID for field  &apos;id&apos;. The identifier generation strategy for this entity requires the ID field to be populated before EntityManager#persist() is called. If you want automatically generated identifiers instead you need to adjust the metadata mapping accordingly. (uncaught exception) at /home/javier/intraway/doctrine_test/sf/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php line 51 [] []&lt;/p&gt;

&lt;p&gt;the only way i get this working is setting the generation strategy to auto but i dont thinks its ok, i want this two entities have the same id and if i make both use generators i cant be surethe ids get generated correctly.&lt;/p&gt;

&lt;p&gt;thanks.&lt;/p&gt;</description>
                <environment></environment>
            <key id="13858">DDC-1928</key>
            <summary>one-to-one relations mapping</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="6">Invalid</resolution>
                                <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="jneyra">Javier Neyra</reporter>
                        <labels>
                    </labels>
                <created>Mon, 16 Jul 2012 21:16:07 +0000</created>
                <updated>Sat, 9 Feb 2013 21:32:00 +0000</updated>
                    <resolved>Sat, 9 Feb 2013 21:32:00 +0000</resolved>
                            <version>2.2.2</version>
                                                <component>ORM</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>2</watches>
                        <comments>
                    <comment id="18322" author="jneyra" created="Tue, 17 Jul 2012 14:39:18 +0000"  >&lt;p&gt;ok. i allmost got it... sorry for the bug post... i was mapping it in the wrong way... i have one remaining issue:&lt;/p&gt;

&lt;p&gt;i found this article explaining how to do what i was trying &lt;a href=&quot;http://docs.doctrine-project.org/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity&quot; class=&quot;external-link&quot;&gt;http://docs.doctrine-project.org/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;so i mapped my entities this way:&lt;/p&gt;

&lt;p&gt;i have an entity named device report: here is the yml for the entity:&lt;/p&gt;

&lt;p&gt;Iway\M2M\ApiBundle\Entity\DeviceReport:&lt;br/&gt;
  type: entity&lt;br/&gt;
  table: srv_m2m_device_report&lt;br/&gt;
  repositoryClass: Iway\M2M\ApiBundle\Entity\DeviceReportRepository&lt;/p&gt;

&lt;p&gt;  id:&lt;br/&gt;
    id:&lt;br/&gt;
      column: reportid&lt;br/&gt;
      type: integer      &lt;br/&gt;
      generator:&lt;br/&gt;
        generator:&lt;br/&gt;
        strategy: SEQUENCE&lt;br/&gt;
      sequenceGenerator:&lt;br/&gt;
        sequenceName: srv_m2m_device_report_seq&lt;br/&gt;
        allocationSize: 10&lt;br/&gt;
        initialValue: 1&lt;/p&gt;

&lt;p&gt;  manyToOne:&lt;br/&gt;
    device:&lt;br/&gt;
      targetEntity: Device&lt;br/&gt;
      inversedBy: reports&lt;br/&gt;
      joinColumn:&lt;br/&gt;
        name: deviceid&lt;br/&gt;
        referencedColumnName: deviceid&lt;/p&gt;

&lt;p&gt;  oneToOne:&lt;br/&gt;
    battery:&lt;br/&gt;
      targetEntity: ReportBattery&lt;br/&gt;
      mappedBy: report        &lt;br/&gt;
  fields:&lt;br/&gt;
    raw_data:&lt;br/&gt;
      type: string&lt;br/&gt;
      length: 4000&lt;br/&gt;
    creation_date:&lt;br/&gt;
      type: datetime&lt;br/&gt;
    data_source:&lt;br/&gt;
      type: string&lt;br/&gt;
      length: 16&lt;br/&gt;
  lifecycleCallbacks: {  }&lt;/p&gt;

&lt;p&gt;the problem is with the battery entity here is the yml:&lt;/p&gt;

&lt;p&gt;Iway\M2M\ApiBundle\Entity\ReportBattery:&lt;br/&gt;
  type: entity&lt;br/&gt;
  table: srv_m2m_report_battery&lt;br/&gt;
  repositoryClass: Iway\M2M\ApiBundle\Entity\ReportBatteryRepository&lt;/p&gt;

&lt;p&gt;  oneToOne:&lt;br/&gt;
    report:      &lt;br/&gt;
      targetEntity: DeviceReport&lt;br/&gt;
      inversedBy: battery&lt;br/&gt;
      joinColumn:&lt;br/&gt;
        name: reportid&lt;br/&gt;
        referencedColumnName: reportid&lt;/p&gt;

&lt;p&gt;  fields:  &lt;br/&gt;
    report_id:&lt;br/&gt;
      id: true&lt;br/&gt;
      type: integer&lt;br/&gt;
      column: reportid&lt;br/&gt;
    battery_voltage:&lt;br/&gt;
      type: integer&lt;br/&gt;
    external_voltage:&lt;br/&gt;
      type: integer&lt;/p&gt;

&lt;p&gt;  lifecycleCallbacks: {  }&lt;/p&gt;

&lt;p&gt;now here is the thing, i can query without any problem on this two entities and joining works well the problem is when i insert:&lt;/p&gt;

&lt;p&gt;here is a simple insert in both entities:&lt;/p&gt;

&lt;p&gt;        $report = new \Iway\M2M\ApiBundle\Entity\DeviceReport();&lt;/p&gt;

&lt;p&gt;        $report-&amp;gt;setDevice($device);&lt;br/&gt;
        $report-&amp;gt;setRawData(&quot;Raw data from EMULATOR&quot;);&lt;br/&gt;
        $report-&amp;gt;setCreationDate(new \DateTime(&quot;now&quot;));&lt;br/&gt;
        $report-&amp;gt;setDataSource(&quot;DEVICE_INFORM&quot;);&lt;br/&gt;
        $em-&amp;gt;persist($report);&lt;/p&gt;

&lt;p&gt;        $battery = new \Iway\M2M\ApiBundle\Entity\ReportBattery();&lt;br/&gt;
        $battery-&amp;gt;setReport($report);&lt;br/&gt;
        $battery-&amp;gt;setReportId($report-&amp;gt;getId());&lt;br/&gt;
        $battery-&amp;gt;setBatteryVoltage(10);&lt;br/&gt;
        $battery-&amp;gt;setExternalVoltage(1000);&lt;br/&gt;
        $em-&amp;gt;persist($battery);&lt;/p&gt;

&lt;p&gt;        $em-&amp;gt;flush();&lt;/p&gt;

&lt;p&gt;if i dont execute this 2 set Methods the query fails&lt;/p&gt;

&lt;p&gt;        $battery-&amp;gt;setReport($report);&lt;br/&gt;
        $battery-&amp;gt;setReportId($report-&amp;gt;getId());&lt;/p&gt;

&lt;p&gt;if i only use setReport i get:&lt;/p&gt;

&lt;p&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;Doctrine\ORM\ORMException&amp;#93;&lt;/span&gt;                                                                                                                                                                &lt;br/&gt;
  Entity of type Iway\M2M\ApiBundle\Entity\ReportBattery is missing an assigned ID for field  &apos;report_id&apos;. The identifier generation strategy for this entity requires the ID field to be p  &lt;br/&gt;
  opulated before EntityManager#persist() is called. If you want automatically generated identifiers instead you need to adjust the metadata mapping accordingly.          &lt;/p&gt;

&lt;p&gt;if i only use: setReportId i get&lt;/p&gt;

&lt;p&gt;  &lt;span class=&quot;error&quot;&gt;&amp;#91;Doctrine\DBAL\Driver\OCI8\OCI8Exception&amp;#93;&lt;/span&gt;                                            &lt;br/&gt;
  ORA-01400: cannot insert NULL into (&quot;IWAYDATA&quot;.&quot;SRV_M2M_REPORT_BATTERY&quot;.&quot;REPORTID&quot;)  &lt;/p&gt;

&lt;p&gt;im mapping something in the wrong way but i cant see what it is..... any help would be great!&lt;br/&gt;
Thanks&lt;/p&gt;</comment>
                    <comment id="18323" author="jneyra" created="Tue, 17 Jul 2012 15:38:49 +0000"  >&lt;p&gt;ok, i want to add a last thing the example &lt;a href=&quot;http://docs.doctrine-project.org/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity&quot; class=&quot;external-link&quot;&gt;http://docs.doctrine-project.org/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;cannot be done using YML (or a least, its not documented)&lt;/p&gt;

&lt;p&gt;what i done is get an empty database a used the example just like it is in the article, then used the task provided to pass from one format to the other (using symfony is ./app/console doctrine:mapping:convert yml /path)&lt;br/&gt;
and get this 2 yml files:&lt;/p&gt;

&lt;p&gt;Acme\DemoBundle\Entity\User:&lt;br/&gt;
    type: entity&lt;br/&gt;
    table: User&lt;br/&gt;
    fields:&lt;br/&gt;
        id:&lt;br/&gt;
            type: integer&lt;br/&gt;
            id: true&lt;br/&gt;
            generator:&lt;br/&gt;
                strategy: IDENTITY&lt;br/&gt;
    lifecycleCallbacks: {  }&lt;/p&gt;

&lt;p&gt;Acme\DemoBundle\Entity\Address:&lt;br/&gt;
    type: entity&lt;br/&gt;
    table: Address&lt;br/&gt;
    oneToOne:&lt;br/&gt;
        user:&lt;br/&gt;
            targetEntity: Acme\DemoBundle\Entity\User&lt;br/&gt;
            cascade: {  }&lt;br/&gt;
            mappedBy: null&lt;br/&gt;
            inversedBy: null&lt;br/&gt;
            joinColumns:&lt;br/&gt;
                user_id:&lt;br/&gt;
                    referencedColumnName: id&lt;br/&gt;
            orphanRemoval: false&lt;br/&gt;
    lifecycleCallbacks: {  }&lt;/p&gt;

&lt;p&gt;when i try to build my schema with this configuration i get:&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;Doctrine\ORM\Mapping\MappingException&amp;#93;&lt;/span&gt;                                                                                             &lt;br/&gt;
  No identifier/primary key specified for Entity &apos;Acme\DemoBundle\Entity\Address&apos;. Every Entity must have an identifier/primary key.&lt;/p&gt;

&lt;p&gt;is there a way to add id: true in a relation on yml or xml configuration? or its only valid using annotations?&lt;/p&gt;</comment>
                    <comment id="19501" author="asm89" created="Sat, 9 Feb 2013 21:32:00 +0000"  >&lt;p&gt;Please use the mailing list or irc channel for support.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>