{"action":"created","issue":{"url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/3790","repository_url":"https://api.github.com/repos/jhipster/generator-jhipster","labels_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/3790/labels{/name}","comments_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/3790/comments","events_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/3790/events","html_url":"https://github.com/jhipster/generator-jhipster/issues/3790","id":162736714,"number":3790,"title":"hibernate lazyinitialisation exception calling getAllEntity with dtos and services","user":{"login":"NilsWild","id":19994535,"avatar_url":"https://avatars.githubusercontent.com/u/19994535?v=3","gravatar_id":"","url":"https://api.github.com/users/NilsWild","html_url":"https://github.com/NilsWild","followers_url":"https://api.github.com/users/NilsWild/followers","following_url":"https://api.github.com/users/NilsWild/following{/other_user}","gists_url":"https://api.github.com/users/NilsWild/gists{/gist_id}","starred_url":"https://api.github.com/users/NilsWild/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NilsWild/subscriptions","organizations_url":"https://api.github.com/users/NilsWild/orgs","repos_url":"https://api.github.com/users/NilsWild/repos","events_url":"https://api.github.com/users/NilsWild/events{/privacy}","received_events_url":"https://api.github.com/users/NilsWild/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-06-28T17:04:24Z","updated_at":"2016-07-07T19:19:09Z","closed_at":null,"body":"##### **Overview of the issue**\r\n\r\nWhen you generate your entities with service and DTOs your calls to the findAll endpoints will fail as the dto is mapped after the transaction is closed. This will lead to a lazyinitialisationexception.\r\n\r\n##### **Motivation for or Use Case** \r\n\r\nThe findAll rest endpoint will return an hibernate lazyinitialisationeception as the transactin is closed before the fields are join fetched.\r\n\r\n##### **JHipster Version(s)** \r\n\r\n3.4.2 as well as earlier versions\r\n\r\n##### **JHipster configuration, a `.yo-rc.json` file generated in the root folder** \r\n\r\n[yo.rc.txt](https://github.com/jhipster/generator-jhipster/files/337587/yo.rc.txt)\r\n\r\n\r\n##### **Entity configuration(s) `entityName.json` files generated in the `.jhipster` directory** \r\n\r\n[Kita.txt](https://github.com/jhipster/generator-jhipster/files/337589/Kita.txt)\r\n[Traeger.txt](https://github.com/jhipster/generator-jhipster/files/337590/Traeger.txt)\r\n\r\n\r\n##### **Browsers and Operating System** \r\n\r\nServer related Problem\r\n\r\n##### **Reproduce the error** \r\n\r\ncreate any entity with dto service and mapping and an lazy relationship and call the rest endpoint to get all entities of that type\r\n\r\n##### **Related issues** \r\n\r\n-\r\n\r\n##### **Suggest a Fix** \r\n\r\nAlternative\r\n1. \r\n\r\nAdd an @Transactional to the getAll endpoint as the Page information is needed to create the appropriate headers (don't know how this would affect performance or anything)\r\n\r\n2.\r\n\r\ncreate a custom \"Page\" object that is returned by the services findAll method that contains the content as well as the headers that is then applied to the response in the resource"},"comment":{"url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/comments/231179844","html_url":"https://github.com/jhipster/generator-jhipster/issues/3790#issuecomment-231179844","issue_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/3790","id":231179844,"user":{"login":"evelknievel","id":20340805,"avatar_url":"https://avatars.githubusercontent.com/u/20340805?v=3","gravatar_id":"","url":"https://api.github.com/users/evelknievel","html_url":"https://github.com/evelknievel","followers_url":"https://api.github.com/users/evelknievel/followers","following_url":"https://api.github.com/users/evelknievel/following{/other_user}","gists_url":"https://api.github.com/users/evelknievel/gists{/gist_id}","starred_url":"https://api.github.com/users/evelknievel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evelknievel/subscriptions","organizations_url":"https://api.github.com/users/evelknievel/orgs","repos_url":"https://api.github.com/users/evelknievel/repos","events_url":"https://api.github.com/users/evelknievel/events{/privacy}","received_events_url":"https://api.github.com/users/evelknievel/received_events","type":"User","site_admin":false},"created_at":"2016-07-07T19:19:09Z","updated_at":"2016-07-07T19:19:09Z","body":"I like the idea of having a good architecture and seperation of concerns. The service layer should NOT handle mapping logic and or have anything to do with DTO's. So i'm very happy with issue #3175 . Actually, I made all these changes by hand in our current project. I think we have to avoid the resources to be transactional. I also ran into this same issue. The problem is we need the total count. \r\nThis can be done by a seperate service call, which performs a countAllEntities(), or we can create a custom wrapper object which contains the List of Entities as well as a total count. I prefer the last option because we have to perform only one service call. Also, the service can work with the spring.data Page object to get the info needed. I don't think this count issue is a reason to make the resources transactional, we should try to avoid that as much as possible."}}
{"actor":{"display_login":"evelknievel"}}