{"action":"created","issue":{"url":"https://api.github.com/repos/ebean-orm/avaje-ebeanorm/issues/547","labels_url":"https://api.github.com/repos/ebean-orm/avaje-ebeanorm/issues/547/labels{/name}","comments_url":"https://api.github.com/repos/ebean-orm/avaje-ebeanorm/issues/547/comments","events_url":"https://api.github.com/repos/ebean-orm/avaje-ebeanorm/issues/547/events","html_url":"https://github.com/ebean-orm/avaje-ebeanorm/issues/547","id":130082227,"number":547,"title":"Removing an object from a @OneToMany collection should set the mapping field to null.","user":{"login":"jokester01au","id":903987,"avatar_url":"https://avatars.githubusercontent.com/u/903987?v=3","gravatar_id":"","url":"https://api.github.com/users/jokester01au","html_url":"https://github.com/jokester01au","followers_url":"https://api.github.com/users/jokester01au/followers","following_url":"https://api.github.com/users/jokester01au/following{/other_user}","gists_url":"https://api.github.com/users/jokester01au/gists{/gist_id}","starred_url":"https://api.github.com/users/jokester01au/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jokester01au/subscriptions","organizations_url":"https://api.github.com/users/jokester01au/orgs","repos_url":"https://api.github.com/users/jokester01au/repos","events_url":"https://api.github.com/users/jokester01au/events{/privacy}","received_events_url":"https://api.github.com/users/jokester01au/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-01-31T05:08:39Z","updated_at":"2016-02-01T01:41:55Z","closed_at":null,"body":"I have the following simple entities:\r\n\r\n```\r\n@Entity\r\n public class Customer extends Model {\r\n\r\n    @OneToMany(cascade = ALL, fetch = EAGER, mappedBy=\"customer\")\r\n    public Set<AnOrder> order;\r\n\r\n    @Id\r\n    public Long id;\r\n }\r\n\r\n@Entity\r\npublic class AnOrder extends Model {\r\n    @ManyToOne\r\n    public Customer customer;\r\n\r\n    @Id\r\n    public Long id;\r\n}\r\n```\r\n\r\nIf I excercise this like so:\r\n\r\n```\r\n        Customer c = new Customer();\r\n        c.order = new HashSet<>();\r\n        AnOrder o = new AnOrder();\r\n        c.order.add(o);\r\n        c.save();\r\n\r\n        Customer cc = Ebean.getServer(null).find(Customer.class).where().eq(\"id\", c.id).findUnique();\r\n        System.out.println(\"Should have an entry: \" + cc.order);\r\n\r\n        cc.order.removeIf(oo -> oo.id == o.id);\r\n        cc.save();\r\n\r\n        cc.refresh();\r\n        System.out.println(\"Should be empty: \" + cc.order);\r\n\r\n        cc = Ebean.getServer(null).find(Customer.class).fetch(\"order\").where().eq(\"id\", c.id).findUnique();\r\n        System.out.println(\"Should be empty: \" + cc.order);\r\n\r\n        AnOrder oo = Ebean.getServer(null).find(AnOrder.class).where().eq(\"id\", o.id).findUnique();\r\n        System.out.println(\"Should be null: \" + oo.customer);\r\n```\r\n\r\nthen I expect `cc.order` to be empty and `oo.customer` to be null. Instead, cc.order still contains an order object and oo.customer still points to c. If I look at the database the customer_id field has not been set to null like I would expect.\r\n\r\nNB I realise that adding @PrivateOwned to the `order` declaration would cause the order to be removed from customer, but it would also delete the order record, which is not what I want.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ebean-orm/avaje-ebeanorm/issues/comments/177692578","html_url":"https://github.com/ebean-orm/avaje-ebeanorm/issues/547#issuecomment-177692578","issue_url":"https://api.github.com/repos/ebean-orm/avaje-ebeanorm/issues/547","id":177692578,"user":{"login":"jokester01au","id":903987,"avatar_url":"https://avatars.githubusercontent.com/u/903987?v=3","gravatar_id":"","url":"https://api.github.com/users/jokester01au","html_url":"https://github.com/jokester01au","followers_url":"https://api.github.com/users/jokester01au/followers","following_url":"https://api.github.com/users/jokester01au/following{/other_user}","gists_url":"https://api.github.com/users/jokester01au/gists{/gist_id}","starred_url":"https://api.github.com/users/jokester01au/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jokester01au/subscriptions","organizations_url":"https://api.github.com/users/jokester01au/orgs","repos_url":"https://api.github.com/users/jokester01au/repos","events_url":"https://api.github.com/users/jokester01au/events{/privacy}","received_events_url":"https://api.github.com/users/jokester01au/received_events","type":"User","site_admin":false},"created_at":"2016-02-01T01:41:55Z","updated_at":"2016-02-01T01:41:55Z","body":"There are periods in my version. They don't seem to be appearing on yours for some reason. I have edited my response to provide much more detail. Please see above."}}