JPA and Threads in play framework

后端 未结 4 1927
Happy的楠姐
Happy的楠姐 2021-01-11 18:07

I\'m trying to create a multithreading server. The problem is that I get the following error: play.exceptions.JPAException: The JPA context is not initialized. JPA Entit

4条回答
  •  借酒劲吻你
    2021-01-11 18:19

    I am guessing your thread is kicked off before Play has a chance to start the JPA Entity Manager.

    If your Model class is annotated with @Entity, then the entity manager would have been created and your error would not appear.

    So, you have a couple of options. Either,

    1. You can create a PlayPlugin, with a lower priority than the Play standard onApplicationStart processes.
    2. You can kickstart your thread from a bootstrap job. This will ensure that Play has had a chance to start up correctly before you start interacting with the server. To see more about bootstrap jobs, see http://www.playframework.org/documentation/1/jobs#concepts

    Personally, I would go with option 2. It is better documented, and play plugins are meant more for extending the framework rather than changing the order of processing.

提交回复
热议问题