{"action":"created","issue":{"url":"https://api.github.com/repos/mongodb/morphia/issues/786","labels_url":"https://api.github.com/repos/mongodb/morphia/issues/786/labels{/name}","comments_url":"https://api.github.com/repos/mongodb/morphia/issues/786/comments","events_url":"https://api.github.com/repos/mongodb/morphia/issues/786/events","html_url":"https://github.com/mongodb/morphia/issues/786","id":80930837,"number":786,"title":"PostPersist issue","user":{"login":"ibugariu","id":12609833,"avatar_url":"https://avatars.githubusercontent.com/u/12609833?v=3","gravatar_id":"","url":"https://api.github.com/users/ibugariu","html_url":"https://github.com/ibugariu","followers_url":"https://api.github.com/users/ibugariu/followers","following_url":"https://api.github.com/users/ibugariu/following{/other_user}","gists_url":"https://api.github.com/users/ibugariu/gists{/gist_id}","starred_url":"https://api.github.com/users/ibugariu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ibugariu/subscriptions","organizations_url":"https://api.github.com/users/ibugariu/orgs","repos_url":"https://api.github.com/users/ibugariu/repos","events_url":"https://api.github.com/users/ibugariu/events{/privacy}","received_events_url":"https://api.github.com/users/ibugariu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-26T11:59:53Z","updated_at":"2015-05-26T12:23:16Z","closed_at":null,"body":"Dear Morphia Team,\r\n\r\nrecently I encountered an issue with latest 1.0.0rc0 release.\r\nMy team uses for a project MongoDB with Morphia. These days I migrated to latest MongoDB 3.0.1 java driver and Morphia 1.0.0.rc0. \r\nThe logic within POJO classes relies on \"_id\" member( annotated with @Id ) to be populated after insert. \r\nI've investigated in debug and I found that DatastoreImpl.postSaveOperations() method calls methods annotated with @PostPersist before to update @Id field:\r\n\r\n```java\r\n  @SuppressWarnings(\"unchecked\")\r\n    private <T> List<Key<T>> postSaveOperations(final Iterable<T> entities, final Map<Object, DBObject> involvedObjects,\r\n                                                final DBCollection collection, final boolean fetchKeys) {\r\n        List<Key<T>> keys = new ArrayList<Key<T>>();\r\n        for (final T entity : entities) {\r\n            final DBObject dbObj = involvedObjects.remove(entity);\r\n                \r\n            mapper.getMappedClass(entity).callLifecycleMethods(PostPersist.class, entity, dbObj);\r\n            \r\n            if (fetchKeys) {\r\n                if (dbObj.get(Mapper.ID_KEY) == null) {\r\n                    throw new MappingException(format(\"Missing _id after save on %s\", entity.getClass().getName()));\r\n                }\r\n                mapper.updateKeyInfo(entity, dbObj, createCache());\r\n                keys.add(new Key<T>((Class<? extends T>) entity.getClass(), collection.getName(), mapper.getId(entity)));\r\n            }\r\n        }\r\n        \r\n        for (Entry<Object, DBObject> entry : involvedObjects.entrySet()) {\r\n            final Object key = entry.getKey();\r\n            mapper.getMappedClass(key)\r\n                  .callLifecycleMethods(PostPersist.class, key, entry.getValue());\r\n            \r\n        }\r\n        return keys;\r\n    }\r\n```\r\n\r\nThis seems to be a bug. I tested with an older version and it worked.\r\nCould you please investigate the issue?\r\nThanks.\r\n"},"comment":{"url":"https://api.github.com/repos/mongodb/morphia/issues/comments/105505275","html_url":"https://github.com/mongodb/morphia/issues/786#issuecomment-105505275","issue_url":"https://api.github.com/repos/mongodb/morphia/issues/786","id":105505275,"user":{"login":"ibugariu","id":12609833,"avatar_url":"https://avatars.githubusercontent.com/u/12609833?v=3","gravatar_id":"","url":"https://api.github.com/users/ibugariu","html_url":"https://github.com/ibugariu","followers_url":"https://api.github.com/users/ibugariu/followers","following_url":"https://api.github.com/users/ibugariu/following{/other_user}","gists_url":"https://api.github.com/users/ibugariu/gists{/gist_id}","starred_url":"https://api.github.com/users/ibugariu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ibugariu/subscriptions","organizations_url":"https://api.github.com/users/ibugariu/orgs","repos_url":"https://api.github.com/users/ibugariu/repos","events_url":"https://api.github.com/users/ibugariu/events{/privacy}","received_events_url":"https://api.github.com/users/ibugariu/received_events","type":"User","site_admin":false},"created_at":"2015-05-26T12:23:16Z","updated_at":"2015-05-26T12:23:16Z","body":"Yes, exactly it worked with an older version of Morphia. The logic is based on the id being available after the insert. We don't want to make a new query to get the _id value.\r\nIs it possible to have a fix for this issue?"}}