<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Sat May 25 22:43:49 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-2025/DDC-2025.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-2025] Doctrine has become too restrictive</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-2025</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;Hi. I am just now trying to convert a PHP project from Symfony 2.0 to Symfony 2.1. Then I also upgraded to the latest version of Doctrine, and I run into a severe problem.&lt;/p&gt;

&lt;p&gt;The application I am converting has two classes for users, one called &quot;User&quot; and the other called &quot;UserName&quot;. They both inherit from &quot;UserBase&quot; and &quot;UserName&quot; is in fact an empty class that just inherit everything from &quot;UserBase&quot;. Why do we have this setup? Because the &quot;User&quot; class is big and ugly with many dependencies form other tables in the database, and every time you load a &quot;User&quot; object it has to do a big join. And even then it has several collections that are lazy-loaded by Doctrine. In contrast &quot;User Name&quot; only contains name and e-mail, and is sufficient for most uses in the application.&lt;/p&gt;

&lt;p&gt;It was not possible to let &quot;UserBase&quot; be this lightweight user object, because it had to be declared as a mapped superclass, and a mapped superclass cannot be an entity. It functioned very well to let a lot of ManyToOne relationships in other classes be to the &quot;UserName&quot; entity, because then it only had to join one table, and it was fast. The full functionality of the &quot;User&quot; class we only need a few places.&lt;/p&gt;

&lt;p&gt;So, all was well and good, until I now got the task of porting the whole thing to the latest version of Symfony. What is wrong? I get the error message &quot;Found entity of type User on association Object#Name, but expecting UserName&quot;. It is in the file UnitOfWork.php around line 740, and it makes my task impossible.&lt;/p&gt;

&lt;p&gt;In some cases I got a &quot;User&quot; object instead of &quot;UserName&quot; object that is declared in the &quot;targetEntity&quot;. And that should be ok, because they come from the same table, and I only want to save the userId on the other object, and all &quot;User&quot; and &quot;UserName&quot; objects are directly form the database and not altered when I try to persist that other object.&lt;/p&gt;

&lt;p&gt;So, please, please, can you make the check a bit less restrictive? May be not just check if the entry is &quot;instanceof&quot; the &quot;targetEntity&quot;, but allow it if the entity refers to the same table. Or only throw the exception if it is a new entity that needs to managed. Or make an annotation that makes it possible to switch this check off? I am a bit desperate here, because I really see no way around this. Thank you.&lt;/p&gt;</description>
                <environment></environment>
            <key id="14030">DDC-2025</key>
            <summary>Doctrine has become too restrictive</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="6" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/closed.png">Closed</status>
                    <resolution id="6">Invalid</resolution>
                    <security id="10000">All</security>
                        <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="terjeb">Terje Br&#229;ten</reporter>
                        <labels>
                    </labels>
                <created>Wed, 12 Sep 2012 20:41:21 +0000</created>
                <updated>Wed, 23 Jan 2013 22:51:12 +0000</updated>
                    <resolved>Wed, 23 Jan 2013 22:51:11 +0000</resolved>
                            <version>Git Master</version>
                                                <component>ORM</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>3</watches>
                        <comments>
                    <comment id="18634" author="beberlei" created="Thu, 13 Sep 2012 06:04:44 +0000"  >&lt;p&gt;Can you show your code that leads to this error? Maybe you can change your mapping slightly to make a refactoring possible. I understand the problem, but I don&apos;t think we can make this check less restrictive, because essentially what you are doing is a hack and this check protects users from a class of very very ugly and hard to debug bugs.&lt;/p&gt;</comment>
                    <comment id="18635" author="terjeb" created="Thu, 13 Sep 2012 07:05:59 +0000"  >&lt;p&gt;Ok, here is some of my code files attached.&lt;br/&gt;
Look in Request.php to see Performer, Initiator and Requestor. Many times they are filled with &quot;UserName&quot; objects, that come from a choice list. And the objects in the choice list comes from the database through Doctrine. But sometimes we also would like to fill those properties on the Request object with a fully fledged &quot;User&quot; object, that typically is the current logged in user.&lt;/p&gt;

&lt;p&gt;The only way around I see is to get another &quot;UserName&quot; object from the DB, that is the same as the &quot;User&quot;, but that seems to be an unnecessary trip to the database that will slow things down.&lt;/p&gt;

&lt;p&gt;Terje&lt;/p&gt;</comment>
                    <comment id="18636" author="terjeb" created="Thu, 13 Sep 2012 07:12:15 +0000"  >&lt;p&gt;By the way, is it not the setters on the object that is supposed to protect programmers from setting the wrong type of object on a property?&lt;/p&gt;

&lt;p&gt;I think it is a bad idea to double that kind of check in the ORM framework, even if it could lead to hard to detect errors. May be you could move the check down into the switch, to the case where you know it will persist the new object?&lt;/p&gt;</comment>
                    <comment id="18667" author="terjeb" created="Tue, 18 Sep 2012 09:22:06 +0000"  >&lt;p&gt;Hi Benjamin,&lt;br/&gt;
Have you thought more about this issue?&lt;/p&gt;

&lt;p&gt;Terje&lt;/p&gt;</comment>
                    <comment id="18668" author="ocramius" created="Tue, 18 Sep 2012 09:36:26 +0000"  >&lt;p&gt;&lt;a href=&quot;http://www.doctrine-project.org/jira/secure/ViewProfile.jspa?name=terjeb&quot; class=&quot;user-hover&quot; rel=&quot;terjeb&quot;&gt;Terje Br&#229;ten&lt;/a&gt; I don&apos;t think you should swap User and UserName objects within your entities, since they have different meaning. That will bring to weird issues and I think you are misusing a feature that otherwise is handled via partial objects.&lt;/p&gt;

&lt;p&gt;Having an object reference User or UserName is quite different in the ORM.&lt;/p&gt;

&lt;p&gt;If you really want to avoid lazy loading and use your own technique instead, use the referenced object&apos;s ID and a service or the EntityManager/EntityRepository API:&lt;/p&gt;


&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
$myObject = $someService-&amp;gt;getSomeStuff();
$id = $myObject-&amp;gt;getUser()-&amp;gt;getId(); &lt;span class=&quot;code-comment&quot;&gt;// proxies have been optimized to avoid queries in &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt;
&lt;/span&gt;$user = $someOtherService-&amp;gt;getUser($id); &lt;span class=&quot;code-comment&quot;&gt;// retrieve the lightweight or heavy version of the User based on your needs&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="18669" author="terjeb" created="Tue, 18 Sep 2012 09:51:56 +0000"  >&lt;p&gt;Hi Marco,&lt;/p&gt;

&lt;p&gt;Thank you for your input, but it does not solve my problem.&lt;/p&gt;

&lt;p&gt;The problem is when I want to save a $myObject in the database with a different or user object id attached to it in a specific property.&lt;br/&gt;
I have a User object, but the property takes a UserName object.&lt;/p&gt;</comment>
                    <comment id="18670" author="terjeb" created="Tue, 18 Sep 2012 10:02:26 +0000"  >&lt;p&gt;Would it be acceptable to make this a configuration option?&lt;/p&gt;

&lt;p&gt;It could be named &quot;targetEntityChecking&quot; whith a default value of &quot;strict&quot;, when target objects are strictly checked for being of the right class, but also with the possibility to set this option to &quot;off&quot;, when you want to leave this check to the property setters where it really belongs.&lt;/p&gt;

&lt;p&gt;Because there really is use cases when it would be really useful to have this check be off, and then the framework would not be a such a straitjacket.&lt;/p&gt;

&lt;p&gt;(I can make a patch to this, if it would be accepted.)&lt;/p&gt;

&lt;p&gt;Terje.&lt;/p&gt;</comment>
                    <comment id="18671" author="ocramius" created="Tue, 18 Sep 2012 10:19:39 +0000"  >&lt;p&gt;&lt;a href=&quot;http://www.doctrine-project.org/jira/secure/ViewProfile.jspa?name=tarjei&quot; class=&quot;user-hover&quot; rel=&quot;tarjei&quot;&gt;Tarjei Huse&lt;/a&gt; I would be against it, since persisting an User or an UserName would be fundamentally different. I really think this is over-optimization work that you are encountering because you are not using a service layer to interact with lazy loading.&lt;/p&gt;</comment>
                    <comment id="18672" author="terjeb" created="Tue, 18 Sep 2012 11:08:33 +0000"  >&lt;p&gt;The actual User or UserName object will always be in the database from before, and will be unchanged. It will not need persisting when the other object is persisted.&lt;/p&gt;

&lt;p&gt;What I want to persist is in my case the &quot;Request&quot; object, that has different properties with the value of users attached.&lt;/p&gt;

&lt;p&gt;So, if I have an User object, will you then force me to get a new UserName object from the DB whith the same ID, so set a UserName valued property on my Request object?&lt;/p&gt;

&lt;p&gt;As I stated before, it should not be the task of Doctrine to check the class of the value in the property, that task belongs to the setter. By duplicating that control, doctrine becomes too restrictive for me.&lt;/p&gt;

&lt;p&gt;Terje&lt;/p&gt;</comment>
                    <comment id="18673" author="ocramius" created="Tue, 18 Sep 2012 11:13:14 +0000"  >&lt;p&gt;&lt;a href=&quot;http://www.doctrine-project.org/jira/secure/ViewProfile.jspa?name=terjeb&quot; class=&quot;user-hover&quot; rel=&quot;terjeb&quot;&gt;Terje Br&#229;ten&lt;/a&gt; since you are using a read-only object, I&apos;d then suggest you to mark it as read only with &lt;a href=&quot;https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/UnitOfWork.php#L3007-3027&quot; class=&quot;external-link&quot;&gt;https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/UnitOfWork.php#L3007-3027&lt;/a&gt; instead. That will also prevent the UnitOfWork from checking it.&lt;/p&gt;

&lt;p&gt;Anyway, I am still against having this different loading method, since the object expected on that relation may be requested by other classes/services that may want the full version of it while you have loaded the partial one, requiring you to have type checks all over the place.&lt;br/&gt;
You are mixing up non homogeneous types, I don&apos;t think this should be supported nor suggested.&lt;/p&gt;</comment>
                    <comment id="18674" author="terjeb" created="Tue, 18 Sep 2012 11:28:31 +0000"  >&lt;p&gt;Hi Marco,&lt;/p&gt;

&lt;p&gt;You are still showing a very poor understanding of the original problem.&lt;/p&gt;

&lt;p&gt;Marking the object as read-only would not help in any way, since that is not checked before this check that is causing trouble: &lt;a href=&quot;https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/UnitOfWork.php#L752-762&quot; class=&quot;external-link&quot;&gt;https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/UnitOfWork.php#L752-762&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And I am not proposing any different loading method of any kind.&lt;/p&gt;

&lt;p&gt;Terje&lt;/p&gt;</comment>
                    <comment id="18675" author="terjeb" created="Tue, 18 Sep 2012 11:42:11 +0000"  >&lt;p&gt;I guess my main beef with this check is that it is unconditional.&lt;br/&gt;
The check is done, weather it is needed or not. If it only could be moved down a few lines to after the case self::STATE_NEW: statement, the only place it would make some sense to check it, all would be well and I could be a happy man and get along with what I was doing before.&lt;/p&gt;

&lt;p&gt;Terje.&lt;/p&gt;</comment>
                    <comment id="18676" author="beberlei" created="Tue, 18 Sep 2012 11:54:12 +0000"  >&lt;p&gt;Hm, that would actually make sense to move the check into STATE_NEW. Good idea, can you open a Pull Request?&lt;/p&gt;

&lt;p&gt;Edit: wait no, thats wrong. You can still put a managed other entity there and its not allowed to be there. &lt;/p&gt;</comment>
                    <comment id="18677" author="terjeb" created="Tue, 18 Sep 2012 12:08:40 +0000"  >&lt;p&gt;But that is my whole point, if it is another managed entity there it should be the task of the setter on the object, and not doctrine, to check if it is allowed to be there or not.&lt;/p&gt;

&lt;p&gt;Could you then at at least allow the check to be conditioned on a doctrine configuration setting?&lt;br/&gt;
(I proposed &quot;targetEntityChecking&quot;, with values &quot;strict&quot; or &quot;off&quot;.)&lt;/p&gt;</comment>
                    <comment id="18687" author="terjeb" created="Thu, 20 Sep 2012 14:15:15 +0000"  >&lt;p&gt;Hi Benjamin.&lt;br/&gt;
Did you have a look to see if I could change the mapping and make a refactoring possible?&lt;br/&gt;
Or do you have any thoughts on weahter the check could be made dependent on a configuration setting?&lt;/p&gt;

&lt;p&gt;Terje.&lt;/p&gt;</comment>
                    <comment id="18730" author="terjeb" created="Tue, 25 Sep 2012 16:23:07 +0000"  >&lt;p&gt;Hi. I would appreciate some more feedback from the lead developer on this issue. Please?&lt;/p&gt;

&lt;p&gt;Should I go ahead and make a working patch for this issue, so that the execution of this test can be configured?&lt;/p&gt;</comment>
                    <comment id="18746" author="terjeb" created="Mon, 1 Oct 2012 21:41:16 +0000"  >&lt;p&gt;I do not like being ignored.&lt;/p&gt;</comment>
                    <comment id="18748" author="beberlei" created="Tue, 2 Oct 2012 08:07:15 +0000"  >&lt;p&gt;&lt;a href=&quot;http://www.doctrine-project.org/jira/secure/ViewProfile.jspa?name=terjeb&quot; class=&quot;user-hover&quot; rel=&quot;terjeb&quot;&gt;Terje Br&#229;ten&lt;/a&gt; I am very sorry that i cant promptly work on this, but I have not very much time lately. I don&apos;t get payed for Doctrine and do this in my free time, same for all the other contributors.&lt;/p&gt;

&lt;p&gt;To make another suggestion. Why are you not using Partial Objects? &lt;a href=&quot;http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/partial-objects.html&quot; class=&quot;external-link&quot;&gt;http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/partial-objects.html&lt;/a&gt; in combination with $em-&amp;gt;refresh($partialuser);?&lt;/p&gt;

&lt;p&gt;I don&apos;t want to make this change more leniant again to be honest, and definately don&apos;t make it configurable. I had countless reports of people that got bitten by this very hard and lost hours of debugging just we didn&apos;t have this check. The way you used assocations was an undocumented hack and you can&apos;t expect this to work indefinately. You can either patch Doctrine yourself or try to fix the code to work with the latest version.&lt;/p&gt;</comment>
                    <comment id="18758" author="terjeb" created="Tue, 2 Oct 2012 14:09:31 +0000"  >&lt;p&gt;Hi Benjamin.&lt;/p&gt;

&lt;p&gt;Thank you for your reply. I can take no for an answer, and I do appreciate that you develop Doctrine in your free time. (What I do not like is the feeling of being ignored when I do not get any response at all.)&lt;/p&gt;

&lt;p&gt;Thank you for pointing me in the direction of partial objects. I will have a look at it and see if that may solve my problem.&lt;/p&gt;

&lt;p&gt;So, just to clarify, do you object to making it configurable because it makes more work for you or do you have other reasons to object? If it is just the former, I would be happy to make the patch myself, if I can just be sure that it will be accepted when I am done.&lt;/p&gt;

&lt;p&gt;Thank you again for all the hard work you are putting into this project for the best of mankind. (Or at least that part of mankind that will be using Doctrine &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;

&lt;p&gt;Terje&lt;/p&gt;</comment>
                    <comment id="18808" author="terjeb" created="Mon, 8 Oct 2012 14:00:01 +0000"  >&lt;p&gt;I still do not like being ignored.&lt;/p&gt;</comment>
                    <comment id="18811" author="ocramius" created="Tue, 9 Oct 2012 09:22:48 +0000"  >&lt;p&gt;I personally think that double-checking at that location is a feature, and as &lt;a href=&quot;http://www.doctrine-project.org/jira/secure/ViewProfile.jspa?name=beberlei&quot; class=&quot;user-hover&quot; rel=&quot;beberlei&quot;&gt;Benjamin Eberlei&lt;/a&gt; exposed, it helps/helped a lot in avoiding hideous bugs (helped me too).&lt;/p&gt;

&lt;p&gt;Should not be removed. If your problem is mainly about performance and you know what you are doing, you can really go with partial objects. If you are sure that the objects already exist in your DB, you can even use things like&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;$em-&amp;gt;getReference($entity, $identifier)&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Does this fit your needs?&lt;/p&gt;</comment>
                    <comment id="18812" author="terjeb" created="Tue, 9 Oct 2012 09:57:49 +0000"  >&lt;p&gt;Hi Marco,&lt;/p&gt;

&lt;p&gt;I guess my one unanswered question is the one about why it cannot be made configurable. Then both parties could be happy.&lt;/p&gt;

&lt;p&gt;So, what is the difference between $em-&amp;gt;getReference($entity, $identifier)&lt;br/&gt;
and $em-&amp;gt;getPartialReference($entity, $identifier)?&lt;br/&gt;
Is the latter one faster?&lt;/p&gt;

&lt;p&gt;Terje.&lt;/p&gt;</comment>
                    <comment id="18835" author="ocramius" created="Sun, 14 Oct 2012 08:30:02 +0000"  >&lt;p&gt;&lt;a href=&quot;http://www.doctrine-project.org/jira/secure/ViewProfile.jspa?name=terjeb&quot; class=&quot;user-hover&quot; rel=&quot;terjeb&quot;&gt;Terje Br&#229;ten&lt;/a&gt; &lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;EntityManager#getReference&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;returns proxies (when the entity is not already available)&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;EntityManager#getPartialReference&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;returns instances of your class with only the identifier set.&lt;/p&gt;

&lt;p&gt;Performance impact is negligible, since neither causes SQL to be thrown at your DB, but &lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;EntityManager#getPartialReference&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt; will produce instances incapable of lazy loading.&lt;/p&gt;</comment>
                    <comment id="19390" author="ocramius" created="Wed, 23 Jan 2013 22:51:12 +0000"  >&lt;p&gt;Unsupported usage of the ORM&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="11322" name="Request.php" size="9729" author="terjeb" created="Thu, 13 Sep 2012 07:05:59 +0000" />
                    <attachment id="11319" name="User.php" size="18719" author="terjeb" created="Thu, 13 Sep 2012 07:05:59 +0000" />
                    <attachment id="11320" name="UserBase.php" size="3351" author="terjeb" created="Thu, 13 Sep 2012 07:05:59 +0000" />
                    <attachment id="11321" name="UserName.php" size="222" author="terjeb" created="Thu, 13 Sep 2012 07:05:59 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>