-
|
Hello, We started our project with PlayFramework 2.6. This version allows us to use jpaApi.em() in our code after invoking jpaApi.withTransaction. and inside this doSomeDbWork there could be a lot of calls to other repositories(there could be chained calls) which need DB connection and we used there jpaApi.em() to perform DB calls. But with PlayFramework 2.8 this possibility was removed and now we need to pass EntityManager as a parameter to each repository method to have a possibility take data from DB. And it is a pain. I am asking an advise maybe I missed something in examples/migration guides and there is some other way to switch to 2.8 version without rewriting most of the project? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Not sure if this is easily possible, but you could mimic what Play 2.8 did and set up your own ThreadLocal to store the EntityManager. You could take a look into the 2.8.x source code how Http.Context was set up. Another possible solution would be that you switch most of your code to dependency injection, so that you inject the repositories into your controllers and into the repository you inject the Also, do you need to use the same transaction for the duration of the whole request? If you need more help let me know. |
Beta Was this translation helpful? Give feedback.
@ppllaxxa You can read through https://www.playframework.com/documentation/3.0.x/JavaHttpContextMigration27