{"action":"created","issue":{"url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/1151","labels_url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/1151/labels{/name}","comments_url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/1151/comments","events_url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/1151/events","html_url":"https://github.com/doctrine/mongodb-odm/pull/1151","id":88842175,"number":1151,"title":"Broken test for #949","user":{"login":"solocommand","id":1778222,"avatar_url":"https://avatars.githubusercontent.com/u/1778222?v=3","gravatar_id":"","url":"https://api.github.com/users/solocommand","html_url":"https://github.com/solocommand","followers_url":"https://api.github.com/users/solocommand/followers","following_url":"https://api.github.com/users/solocommand/following{/other_user}","gists_url":"https://api.github.com/users/solocommand/gists{/gist_id}","starred_url":"https://api.github.com/users/solocommand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solocommand/subscriptions","organizations_url":"https://api.github.com/users/solocommand/orgs","repos_url":"https://api.github.com/users/solocommand/repos","events_url":"https://api.github.com/users/solocommand/events{/privacy}","received_events_url":"https://api.github.com/users/solocommand/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/doctrine/mongodb-odm/labels/task","name":"task","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/doctrine/mongodb-odm/milestones/1","html_url":"https://github.com/doctrine/mongodb-odm/milestones/1.0.0","labels_url":"https://api.github.com/repos/doctrine/mongodb-odm/milestones/1/labels","id":543770,"number":1,"title":"1.0.0","description":"","creator":{"login":"jmikola","id":244663,"avatar_url":"https://avatars.githubusercontent.com/u/244663?v=3","gravatar_id":"","url":"https://api.github.com/users/jmikola","html_url":"https://github.com/jmikola","followers_url":"https://api.github.com/users/jmikola/followers","following_url":"https://api.github.com/users/jmikola/following{/other_user}","gists_url":"https://api.github.com/users/jmikola/gists{/gist_id}","starred_url":"https://api.github.com/users/jmikola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmikola/subscriptions","organizations_url":"https://api.github.com/users/jmikola/orgs","repos_url":"https://api.github.com/users/jmikola/repos","events_url":"https://api.github.com/users/jmikola/events{/privacy}","received_events_url":"https://api.github.com/users/jmikola/received_events","type":"User","site_admin":false},"open_issues":49,"closed_issues":29,"state":"open","created_at":"2014-01-22T04:49:23Z","updated_at":"2015-06-16T21:29:39Z","due_on":null,"closed_at":null},"comments":5,"created_at":"2015-06-16T21:14:10Z","updated_at":"2015-06-17T04:27:48Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/doctrine/mongodb-odm/pulls/1151","html_url":"https://github.com/doctrine/mongodb-odm/pull/1151","diff_url":"https://github.com/doctrine/mongodb-odm/pull/1151.diff","patch_url":"https://github.com/doctrine/mongodb-odm/pull/1151.patch"},"body":"This includes a requested broken test demonstrating the failure reported in #949.\r\n\r\nWhen attempting to persist a document containing a reference that previously existed in the identity map (after a flush/clear) a `RuntimeException: Cannot create a DBRef without an identifier. UnitOfWork::getDocumentIdentifier() did not return an identifier for class x` exception is thrown.\r\n\r\nI've run into this issue myself several times, as @vmattila pointed out it seems to stem from retaining an existing document that had been retrieved from the database (or persisted with a flush/clear afterwards), and attempting to persist a new document with the old document referenced (rather than retrieving it again after the clear in the UoW)."},"comment":{"url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/comments/112649410","html_url":"https://github.com/doctrine/mongodb-odm/pull/1151#issuecomment-112649410","issue_url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/1151","id":112649410,"user":{"login":"vmattila","id":435124,"avatar_url":"https://avatars.githubusercontent.com/u/435124?v=3","gravatar_id":"","url":"https://api.github.com/users/vmattila","html_url":"https://github.com/vmattila","followers_url":"https://api.github.com/users/vmattila/followers","following_url":"https://api.github.com/users/vmattila/following{/other_user}","gists_url":"https://api.github.com/users/vmattila/gists{/gist_id}","starred_url":"https://api.github.com/users/vmattila/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vmattila/subscriptions","organizations_url":"https://api.github.com/users/vmattila/orgs","repos_url":"https://api.github.com/users/vmattila/repos","events_url":"https://api.github.com/users/vmattila/events{/privacy}","received_events_url":"https://api.github.com/users/vmattila/received_events","type":"User","site_admin":false},"created_at":"2015-06-17T04:27:48Z","updated_at":"2015-06-17T04:27:48Z","body":"This exception to happen, to be honest, is a kind of sign that the application design might be bad (at least it was in my case :). Definitely +1 for a better exception.\r\n\r\nIf we'd use `cascade=\"persist\"` didn't this lead to re-persisting the referenced document to database, that most likely ends up to an error due duplicate `_id`?\r\n\r\nHow about ODM trying to `merge` the detached document automatically if the `_id` is known? I did recently submitted an idea #1076 that could also benefit of this behaviour."}}