{"action":"opened","issue":{"url":"https://api.github.com/repos/actframework/actframework/issues/823","repository_url":"https://api.github.com/repos/actframework/actframework","labels_url":"https://api.github.com/repos/actframework/actframework/issues/823/labels{/name}","comments_url":"https://api.github.com/repos/actframework/actframework/issues/823/comments","events_url":"https://api.github.com/repos/actframework/actframework/issues/823/events","html_url":"https://github.com/actframework/actframework/issues/823","id":358242825,"node_id":"MDU6SXNzdWUzNTgyNDI4MjU=","number":823,"title":"Apply new scope for implicit transaction","user":{"login":"greenlaw110","id":216930,"node_id":"MDQ6VXNlcjIxNjkzMA==","avatar_url":"https://avatars3.githubusercontent.com/u/216930?v=4","gravatar_id":"","url":"https://api.github.com/users/greenlaw110","html_url":"https://github.com/greenlaw110","followers_url":"https://api.github.com/users/greenlaw110/followers","following_url":"https://api.github.com/users/greenlaw110/following{/other_user}","gists_url":"https://api.github.com/users/greenlaw110/gists{/gist_id}","starred_url":"https://api.github.com/users/greenlaw110/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/greenlaw110/subscriptions","organizations_url":"https://api.github.com/users/greenlaw110/orgs","repos_url":"https://api.github.com/users/greenlaw110/repos","events_url":"https://api.github.com/users/greenlaw110/events{/privacy}","received_events_url":"https://api.github.com/users/greenlaw110/received_events","type":"User","site_admin":false},"labels":[{"id":157039278,"node_id":"MDU6TGFiZWwxNTcwMzkyNzg=","url":"https://api.github.com/repos/actframework/actframework/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":{"login":"greenlaw110","id":216930,"node_id":"MDQ6VXNlcjIxNjkzMA==","avatar_url":"https://avatars3.githubusercontent.com/u/216930?v=4","gravatar_id":"","url":"https://api.github.com/users/greenlaw110","html_url":"https://github.com/greenlaw110","followers_url":"https://api.github.com/users/greenlaw110/followers","following_url":"https://api.github.com/users/greenlaw110/following{/other_user}","gists_url":"https://api.github.com/users/greenlaw110/gists{/gist_id}","starred_url":"https://api.github.com/users/greenlaw110/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/greenlaw110/subscriptions","organizations_url":"https://api.github.com/users/greenlaw110/orgs","repos_url":"https://api.github.com/users/greenlaw110/repos","events_url":"https://api.github.com/users/greenlaw110/events{/privacy}","received_events_url":"https://api.github.com/users/greenlaw110/received_events","type":"User","site_admin":false},"assignees":[{"login":"greenlaw110","id":216930,"node_id":"MDQ6VXNlcjIxNjkzMA==","avatar_url":"https://avatars3.githubusercontent.com/u/216930?v=4","gravatar_id":"","url":"https://api.github.com/users/greenlaw110","html_url":"https://github.com/greenlaw110","followers_url":"https://api.github.com/users/greenlaw110/followers","following_url":"https://api.github.com/users/greenlaw110/following{/other_user}","gists_url":"https://api.github.com/users/greenlaw110/gists{/gist_id}","starred_url":"https://api.github.com/users/greenlaw110/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/greenlaw110/subscriptions","organizations_url":"https://api.github.com/users/greenlaw110/orgs","repos_url":"https://api.github.com/users/greenlaw110/repos","events_url":"https://api.github.com/users/greenlaw110/events{/privacy}","received_events_url":"https://api.github.com/users/greenlaw110/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/actframework/actframework/milestones/57","html_url":"https://github.com/actframework/actframework/milestone/57","labels_url":"https://api.github.com/repos/actframework/actframework/milestones/57/labels","id":3250670,"node_id":"MDk6TWlsZXN0b25lMzI1MDY3MA==","number":57,"title":"1.8.8","description":"","creator":{"login":"greenlaw110","id":216930,"node_id":"MDQ6VXNlcjIxNjkzMA==","avatar_url":"https://avatars3.githubusercontent.com/u/216930?v=4","gravatar_id":"","url":"https://api.github.com/users/greenlaw110","html_url":"https://github.com/greenlaw110","followers_url":"https://api.github.com/users/greenlaw110/followers","following_url":"https://api.github.com/users/greenlaw110/following{/other_user}","gists_url":"https://api.github.com/users/greenlaw110/gists{/gist_id}","starred_url":"https://api.github.com/users/greenlaw110/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/greenlaw110/subscriptions","organizations_url":"https://api.github.com/users/greenlaw110/orgs","repos_url":"https://api.github.com/users/greenlaw110/repos","events_url":"https://api.github.com/users/greenlaw110/events{/privacy}","received_events_url":"https://api.github.com/users/greenlaw110/received_events","type":"User","site_admin":false},"open_issues":95,"closed_issues":63,"state":"open","created_at":"2018-04-08T19:57:55Z","updated_at":"2018-09-07T23:48:21Z","due_on":null,"closed_at":null},"comments":0,"created_at":"2018-09-07T23:48:21Z","updated_at":"2018-09-07T23:48:21Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"At the moment the **implicit** of (SQL) Transaction scope starts before request handler is invoked and after result has been rendered into response. However there is a subtle issue with Generated ID value. With the following entity class:\r\n\r\n```java\r\n@Entity(name = \"user\")\r\npublic class User implement SimpleBean {\r\n    @ID\r\n    @GeneratedValue(strategy = GenerationType.IDENTITY)\r\n    public Integer id;\r\n    public String name;\r\n    ...\r\n}\r\n```\r\n\r\nAnd the following service endpoint:\r\n\r\n```java\r\n@UrlContext(\"users\")\r\npublic class UserService {\r\n    @Inject\r\n    private JPADao<User> userDao;\r\n\r\n    @PostAction\r\n    public User create(User user) {\r\n        return userDao.save(user);\r\n    }\r\n    ...\r\n}\r\n```\r\n\r\nThe above code aims to return the new created user with the id value been assigned. However because the `id` field is generated with `GenerationType.IDENTITY` strategy, meaning the field won't be update until transaction is committed, ie. when the result has been rendered into response already. Hence it is not possible to get the new `id` value in the return result. A workaround is to add `@Transactional` annotation to the `create(User)` method in order to commit the transaction at method return. \r\n\r\nThis change request is to create new scope for implicit transaction to make sure it get committed or rollback before rendering occur.\r\n\r\nAnother thing is we want to support the case when only `id` is returned by using function:\r\n\r\n```java\r\n    @PostAction\r\n    public $.Producer<Integer> create(final User user) {\r\n        userDao.save(user);\r\n        return new $.Producer<Integer>() {\r\n            public Integer get() {return user.id;}\r\n        }\r\n    }\r\n```\r\n\r\n"}}
{"actor":{"display_login":"greenlaw110"}}