{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/882","labels_url":"https://api.github.com/repos/realm/realm-java/issues/882/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/882/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/882/events","html_url":"https://github.com/realm/realm-java/issues/882","id":58461135,"number":882,"title":"Duplicate entries using copyToRealmOrUpdate() despite @PrimaryKey","user":{"login":"jenzz","id":1798455,"avatar_url":"https://avatars.githubusercontent.com/u/1798455?v=3","gravatar_id":"","url":"https://api.github.com/users/jenzz","html_url":"https://github.com/jenzz","followers_url":"https://api.github.com/users/jenzz/followers","following_url":"https://api.github.com/users/jenzz/following{/other_user}","gists_url":"https://api.github.com/users/jenzz/gists{/gist_id}","starred_url":"https://api.github.com/users/jenzz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenzz/subscriptions","organizations_url":"https://api.github.com/users/jenzz/orgs","repos_url":"https://api.github.com/users/jenzz/repos","events_url":"https://api.github.com/users/jenzz/events{/privacy}","received_events_url":"https://api.github.com/users/jenzz/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-java/labels/support","name":"support","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-02-21T14:31:03Z","updated_at":"2015-02-24T14:09:24Z","closed_at":"2015-02-24T14:09:24Z","body":"Hi there!\r\n\r\nI'm using the latest version of Realm: **0.79.1**\r\nI noticed a weird behaviour when using `copyToRealmOrUpdate()` resulting in duplicate entries.\r\nMaybe this is the expected behaviour. I'm not sure.\r\n\r\nI've created a sample project: https://bitbucket.org/jenzz/realm-primarykey-bug/src\r\n\r\nSo what's the problem? The following code...\r\n\r\n```\r\nRealm realm = Realm.getInstance(this);\r\nrealm.beginTransaction();\r\n\r\nAddress address = new Address(\"123 456\", \"High street\");\r\n\r\nUser user1 = new User(1, address);\r\nrealm.copyToRealmOrUpdate(user1);\r\n\r\n// Note: Same id and same address!\r\nUser user2 = new User(1, address);\r\nrealm.copyToRealmOrUpdate(user2);\r\n\r\nrealm.commitTransaction();\r\nrealm.close();\r\n```\r\n\r\n...generates the following DB:\r\n\r\n![screen shot 2015-02-21 at 14 09 39](https://cloud.githubusercontent.com/assets/1798455/6314381/28f4b8b0-b9d4-11e4-9a45-b0db059a4f9e.png)\r\n\r\n\r\nGiven that `user2` has the **same id and address** as `user1`,\r\nI would expect the `Address` table to just update the currently mapped entry instead of inserting a duplicate.\r\n"},"comment":{"url":"https://api.github.com/repos/realm/realm-java/issues/comments/75761829","html_url":"https://github.com/realm/realm-java/issues/882#issuecomment-75761829","issue_url":"https://api.github.com/repos/realm/realm-java/issues/882","id":75761829,"user":{"login":"cmelchior","id":406066,"avatar_url":"https://avatars.githubusercontent.com/u/406066?v=3","gravatar_id":"","url":"https://api.github.com/users/cmelchior","html_url":"https://github.com/cmelchior","followers_url":"https://api.github.com/users/cmelchior/followers","following_url":"https://api.github.com/users/cmelchior/following{/other_user}","gists_url":"https://api.github.com/users/cmelchior/gists{/gist_id}","starred_url":"https://api.github.com/users/cmelchior/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmelchior/subscriptions","organizations_url":"https://api.github.com/users/cmelchior/orgs","repos_url":"https://api.github.com/users/cmelchior/repos","events_url":"https://api.github.com/users/cmelchior/events{/privacy}","received_events_url":"https://api.github.com/users/cmelchior/received_events","type":"User","site_admin":false},"created_at":"2015-02-24T14:09:24Z","updated_at":"2015-02-24T14:09:24Z","body":"Hi @jenzz \r\nI assume the above answered your question. Feel free to add additional info if that is not the case."}}