{"action":"created","issue":{"url":"https://api.github.com/repos/javers/javers/issues/712","repository_url":"https://api.github.com/repos/javers/javers","labels_url":"https://api.github.com/repos/javers/javers/issues/712/labels{/name}","comments_url":"https://api.github.com/repos/javers/javers/issues/712/comments","events_url":"https://api.github.com/repos/javers/javers/issues/712/events","html_url":"https://github.com/javers/javers/issues/712","id":360563673,"node_id":"MDU6SXNzdWUzNjA1NjM2NzM=","number":712,"title":"Error while saving composite entity having another entity id as null","user":{"login":"vtiwari2134","id":34383551,"node_id":"MDQ6VXNlcjM0MzgzNTUx","avatar_url":"https://avatars2.githubusercontent.com/u/34383551?v=4","gravatar_id":"","url":"https://api.github.com/users/vtiwari2134","html_url":"https://github.com/vtiwari2134","followers_url":"https://api.github.com/users/vtiwari2134/followers","following_url":"https://api.github.com/users/vtiwari2134/following{/other_user}","gists_url":"https://api.github.com/users/vtiwari2134/gists{/gist_id}","starred_url":"https://api.github.com/users/vtiwari2134/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vtiwari2134/subscriptions","organizations_url":"https://api.github.com/users/vtiwari2134/orgs","repos_url":"https://api.github.com/users/vtiwari2134/repos","events_url":"https://api.github.com/users/vtiwari2134/events{/privacy}","received_events_url":"https://api.github.com/users/vtiwari2134/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":18,"created_at":"2018-09-15T18:23:47Z","updated_at":"2018-09-29T15:08:24Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Following exception occurs while saving entity with javers auditing enabled in spring - \r\nJaversException ENTITY_INSTANCE_WITH_NULL_ID: Found Entity instance 'com.test.entity.DepartmentEntity' with null idProperty 'id'\r\n\r\nI think the issue is with <code>JaversSpringDataAuditableRepositoryAspect.class</code> having aspect on save (<code>@AfterReturning(\"execution(public * save(..)) && this(org.springframework.data.repository.CrudRepository)\")</code>) method. In this the entity is audited on the argument passed to save method but auditing should be performed on return entity that is saved by hibernate.\r\n\r\nIssue arises because whenever detached entity is saved to persist hibernate tries to merge the entity creating new entity in hibernate session. Hence the return entity is different from the entity passed to save.\r\nThat why the Aspect <code>public void onSaveExecuted(JoinPoint pjp) {\r\n    this.onVersionEvent(pjp, this.saveHandler);\r\n  }</code> should evaluate the return entity from <code>save</code> method.\r\n\r\n**Sample spring project to replicate bug -**\r\n[test.zip](https://github.com/javers/javers/files/2385977/test.zip)\r\n\r\nTo replicate issue run JaversExceptionTest  test case. This test class contains 2 test one saves entity without having auditing enabled and one with javers auditing enabled.\r\nIn first case EmployeeEntity is saved successfully in db while second case throws error : -\r\n\r\n<code>JaversException ENTITY_INSTANCE_WITH_NULL_ID: Found Entity instance 'com.test.entity.DepartmentEntity' with null idProperty 'id'\r\n\r\n\tat org.javers.core.metamodel.type.EntityType.getIdOf(EntityType.java:88)\r\n\tat org.javers.core.metamodel.object.InstanceId.createFromInstance(InstanceId.java:28)\r\n\tat org.javers.core.metamodel.object.GlobalIdFactory.createId(GlobalIdFactory.java:49)\r\n\tat org.javers.core.graph.LiveCdoFactory.create(LiveCdoFactory.java:25)\r\n\tat org.javers.core.graph.LiveCdoFactory.create(LiveCdoFactory.java:10)\r\n\tat org.javers.core.graph.EdgeBuilder.buildSingleEdge(EdgeBuilder.java:30)</code>\r\n\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/javers/javers/issues/comments/425652079","html_url":"https://github.com/javers/javers/issues/712#issuecomment-425652079","issue_url":"https://api.github.com/repos/javers/javers/issues/712","id":425652079,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNTY1MjA3OQ==","user":{"login":"vtiwari2134","id":34383551,"node_id":"MDQ6VXNlcjM0MzgzNTUx","avatar_url":"https://avatars2.githubusercontent.com/u/34383551?v=4","gravatar_id":"","url":"https://api.github.com/users/vtiwari2134","html_url":"https://github.com/vtiwari2134","followers_url":"https://api.github.com/users/vtiwari2134/followers","following_url":"https://api.github.com/users/vtiwari2134/following{/other_user}","gists_url":"https://api.github.com/users/vtiwari2134/gists{/gist_id}","starred_url":"https://api.github.com/users/vtiwari2134/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vtiwari2134/subscriptions","organizations_url":"https://api.github.com/users/vtiwari2134/orgs","repos_url":"https://api.github.com/users/vtiwari2134/repos","events_url":"https://api.github.com/users/vtiwari2134/events{/privacy}","received_events_url":"https://api.github.com/users/vtiwari2134/received_events","type":"User","site_admin":false},"created_at":"2018-09-29T15:08:24Z","updated_at":"2018-09-29T15:08:24Z","author_association":"CONTRIBUTOR","body":"@bartoszwalacik Thats great! Happy to contribute. :) Thanks!"}}
{"actor":{"display_login":"vtiwari2134"}}